+ 1

Add variables

I want to add two variables but I am unable I put the add sign between variables but the don't add up simply they are written here is the code you can see https://code.sololearn.com/Wl3lRhhh73Xl/?ref=app

17th Oct 2020, 1:03 PM
Charchit Dahiya
Charchit Dahiya - avatar
4 Antworten
+ 1
Prompt returns a string ,and usuage of "+" on strings concatenates them ,instead cast the result to int and then perform addition , w=parseInt(prompt())
17th Oct 2020, 1:07 PM
Abhay
Abhay - avatar
+ 1
Input return you data in string form that why + is acting as concatinator. For maths do it as var c = parseInt(w)+parseInt(y);
17th Oct 2020, 1:08 PM
Divya Mohan
Divya Mohan - avatar
+ 1
The problem solved thanks to both
17th Oct 2020, 1:14 PM
Charchit Dahiya
Charchit Dahiya - avatar
0
ParseInt is not defined
17th Oct 2020, 1:13 PM
Charchit Dahiya
Charchit Dahiya - avatar