Click here to Skip to main content
15,891,976 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
var a = prompt("Input a number");
var b = prompt("Input second number");
var c = "a" + "b";
alert(a + b);
JavaScript



What I have tried:

Now I have tried typing two numbers and they don't add up. Example 5 + 5 is supposed to be 10 but it shows as 55. What am I suppose to do here?
Posted
Updated 27-Mar-18 0:21am

You need to change the code to parse the input to integer. Here is an example. JavaScript parseInt() Function[^]
 
Share this answer
 
Comments
Member 13748876 27-Mar-18 5:54am    
But this only allows predefined values for the variables. What if I want the suers to put their own value after they run the code?
Richard Deeming 27-Mar-18 8:40am    
var a = parseInt(prompt("Input a number"), 10);
Member 13748876 27-Mar-18 10:24am    
Thank you so much! It finally worked!
Go to JavaScript Variables[^] and study the documentation. Javascript is a much more dynamic language than most.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900