+ 3

Why d (variable)is treated as string

I don't know why it's happening d is treated as string https://code.sololearn.com/WruS83awNHHw/?ref=app

15th Nov 2017, 10:51 AM
Vaibhav Kushwaha
Vaibhav Kushwaha - avatar
5 ответов
+ 3
That's because prompt accepts strings only. Do like the following: var y = Number(prompt("Enter year"));
15th Nov 2017, 10:57 AM
Witty Phantom
Witty Phantom - avatar
+ 5
use parseInt to convert it to integer.
15th Nov 2017, 10:58 AM
Md. Nafis Ul Haque Shifat
Md. Nafis Ul Haque Shifat - avatar
+ 2
thx a lot
15th Nov 2017, 10:57 AM
Vaibhav Kushwaha
Vaibhav Kushwaha - avatar
+ 2
how to split a numeric data input like I have to use 3 of 5340
15th Nov 2017, 11:09 AM
Vaibhav Kushwaha
Vaibhav Kushwaha - avatar
0
Covert it to a string, then get the index of your number and catch it with substr. For example, var x = 5340 alert(x.toString().substr(1,1))
15th Nov 2017, 11:13 AM
Witty Phantom
Witty Phantom - avatar