0

Addition in JS?

I'm fairly new to code, but I've been trying to make a prompt-based calculator. Everything works fine, but addition works weirdly. Like, say if we did 7 + 5 it would come out as 75. Help?

16th May 2017, 2:04 AM
Avyaansh
Avyaansh  - avatar
5 Antworten
+ 5
Post the link to your code.
16th May 2017, 2:57 AM
Wisdom Abioye
Wisdom Abioye - avatar
+ 4
If you want to use only one prompt then you can use the native eval function to evaluate the statement. This is a working prompt calculator: alert(eval(prompt("Please enter a calculation:"))); (Input would look like "7+7*8") And if you want to show the user multiple prompt, you could convert the string of each prompt to a number: var firstNumber = Number(prompt("Enter your first number:")); var secondNumber = Number(prompt("Enter your second Number")); alert(firstNumber +" + "+ secondNumber+" = "+ (firstNumber+secondNumber) );
16th May 2017, 4:23 AM
Tim G
Tim G - avatar
0
Maybe you declared 7 and 5 as strings? Where are your codes?
16th May 2017, 2:18 AM
Sabrina Aviles
0
just transorm it into numbers and you're done. You can check this one...but it uses JQ :D https://code.sololearn.com/WDiuu4Iu0j0D
16th May 2017, 2:35 AM
Rose Sevenyears
Rose  Sevenyears - avatar