Page 1 of 1

newbie: isNaN

Posted: Sat Nov 07, 2009 9:34 pm
by tabutcher
hello,
basically what I want is to have a while loop that will prompt the user continuously until he/she inputs a number. I entered some test data and found that if I put for example '1a' it will except it.
thank you in advance

Briefly:
I prompt for a value
check to see if value is only two digits long
convert string to int
check value is a number
Below is my code:

Code: Select all

 do{    num1 = prompt("Enter number 1", "");    if(num1.length > 2)    {        valid = false;    }    else    {        valid = true;    }    num1 = parseInt(num1);}while(isNaN(num1) || valid == false); 

Re: newbie: isNaN

Posted: Wed Nov 11, 2009 2:11 am
by urooj786
isNaN function is used only to check that entered value is a numericor not......