+ 4
Why does the "+" operator not work?
I made a simple calculator in javascript just to test the waters and for some reason the "+" operator doesn't add the numbers together but instead just outputs them side by side. (Ex: 2 + 2 = 22) I've looked at other people's codes and I've written the "Alert (numx + numy);" just like other people. My initial thought was maybe Alert doesn't support that operator so I tried "document.write (numx + numy);" and got the same result. https://code.sololearn.com/Wfmct110wltw/?ref=app
3 odpowiedzi
+ 6
Even though you input numbers in prompt, prompt output it as string. So you need to convert them to numbers using Number or parseInt functions:
var numx = Number(prompt("Enter the first number."));
var op = prompt("Enter a simple operator.");
var numy = Number(prompt("Enter the second number."));
+ 3
Thank you!
0
Tim me too bro