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?
5 Respostas
+ 5
Post the link to your code.
+ 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) );
0
Maybe you declared 7 and 5 as strings? Where are your codes?
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