newbie: isNaN
Posted: Sat Nov 07, 2009 9:34 pm
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:
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);