parseInt and isNan example
I am studying web development and at the moment I am learning Java and JS, so I thought this following simple code would be handy for newbies :)
var age = prompt ('How old are you?'); //a text box will pop up asking the question, and the answer is saved in age
age = parseInt(age);// the user's answer, age, will be checked whether it's and integer or not.
if (isNaN(age))//isNan looks and decides whether the age is NOT a number
age = prompt("You have not entered a number yet, so how old are you? ");//if isNaN finds out that age doesn't contain a number then a new sentence will be displayed.
document.write('You are '+age+' years old.');//if an integer is stored , then the code will display the value that was originally entered.