0

Pls why does this code treat the inputs as strings and not numbers. And how can I make it treat it as numbers??

https://code.sololearn.com/WXQ7bFqSFNRT/?ref=app

21st Jul 2018, 5:55 PM
Emeruche Ikenna Cole
Emeruche Ikenna Cole - avatar
5 Answers
+ 8
use parseInt() to conversion var n1 = parseInt(prompt("Enter first number")); var n2 = parseInt(prompt("Enter second number")); document.write(n1 + n2)
21st Jul 2018, 6:01 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 7
parse is used to convert one data type to other like in above code string is converted in integer value
21st Jul 2018, 6:04 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 6
yes it will convert in integer value here is a good link regarding this go through this it will give you some more information https://googleweblight.com/i?u=https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/parseInt&hl=en-IN
21st Jul 2018, 6:08 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 1
What's parseInt? What does it mean pls
21st Jul 2018, 6:03 PM
Emeruche Ikenna Cole
Emeruche Ikenna Cole - avatar
0
GAWEN STEASY So if I use it in a string it tries to convert it to an integer?
21st Jul 2018, 6:06 PM
Emeruche Ikenna Cole
Emeruche Ikenna Cole - avatar