I wrote a code with intention to obtain two numerical inputs and add them but its not working: pls help var V = prompt("enter V"); var U = prompt("enter U"); var ln = U+V; document.write(ln); | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I wrote a code with intention to obtain two numerical inputs and add them but its not working: pls help var V = prompt("enter V"); var U = prompt("enter U"); var ln = U+V; document.write(ln);

10th Dec 2016, 2:44 AM
Nwaburu Emeka Christian
Nwaburu Emeka Christian - avatar
7 Answers
+ 6
input boxes are elements of html they can be made by simply using input tag. and valueless can be put. you can see codes many codes in sololearn too have it you can see my code too it has input too.
10th Dec 2016, 2:48 PM
Sandeep Chatterjee
+ 2
they inputs are strings you have to manually set by using par seInt(). this problem appears in prompt use input tag there it converts numbers to integers and it can be custmoized
10th Dec 2016, 6:53 AM
Sandeep Chatterjee
+ 2
just convert the value obtained in prompt to integer becuase they are string 6 + 6 will show 66 instead of 12. pa rseInt(6)+ porseInt(6) is 12. so you can either put them inside prompt() or convert later another thing I suggested was that you can use input boxes instead of prompt you can customize as you like for example see my code validate it and there is no need of conversion
10th Dec 2016, 10:51 AM
Sandeep Chatterjee
+ 2
This problem doesn't appear when you multiply or divide because those are strictly mathematical operators. + can be used to be perform addition of integers but also be used to combine two strings such as in concatenation.
20th Dec 2016, 10:04 PM
Robert Jones
Robert Jones - avatar
+ 1
thanks, though I don't understand it properly... can u pls help me rewrite the code in a way it will work? I wonder why this problem doesn't come up when am subtracting or multiplying the inputs.
10th Dec 2016, 8:19 AM
Nwaburu Emeka Christian
Nwaburu Emeka Christian - avatar
+ 1
pls what are input boxes and how do i use them
10th Dec 2016, 1:35 PM
Nwaburu Emeka Christian
Nwaburu Emeka Christian - avatar
+ 1
pls what are input boxes and how do i use them
10th Dec 2016, 1:35 PM
Nwaburu Emeka Christian
Nwaburu Emeka Christian - avatar