Why d (variable)is treated as string | Sololearn: Learn to code for FREE!


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

11/15/2017 10:51:47 AM

Vaibhav Kushwaha

5 Answers

New Answer


That's because prompt accepts strings only. Do like the following: var y = Number(prompt("Enter year"));


use parseInt to convert it to integer.



how to split a numeric data input like I have to use 3 of 5340


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))