New course! Every coder should learn Generative AI!
Try a free lesson+ 2
Prompting User to Try Again!
Iโm a beginner. Iโm desperate to know how this is done, - I can prompt a user to type something, - But I donโt know how to prompt user when they donโt meet my requirement, Like I want the input to be a Number or a String Of Words; So in case of a number not written the result is NaN. - Now I want to know rather than NaN, how to alert the user to type the correct requirement and Type a code where itโs an infinite loop until they type the correct number or string? Hope Someone Helps! Thanks ๐
4 Answers
+ 9
Modification to @areila's code -
var number;
while(isNaN(number)){
number = prompt("No.")
}
+ 3
var number;
while(number.isNan()){
number = prompt(โPlease input a number:โ)
}
+ 2
@Ariela, Thatโs all I must type to prompt user and say type again if they entered the wrong value? Coz thatโs not working thatโs y asked!
Btw thanks for seeing my question and answering it! ๐๐๐๐ป
+ 2
@Nikhil, Thanks bro! Itโs working now ๐๐๐๐ป๐๐ป