0
Pls why does this code treat the inputs as strings and not numbers. And how can I make it treat it as numbers??
5 odpowiedzi
+ 8
use parseInt() to conversion
var n1 = parseInt(prompt("Enter first number"));
var n2 = parseInt(prompt("Enter second number"));
document.write(n1 + n2)
+ 7
parse is used to convert one data type to other like in above code string is converted in integer value
+ 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
+ 1
What's parseInt? What does it mean pls
0
GAWEN STEASY So if I use it in a string it tries to convert it to an integer?