Prompting User to Try Again! | Sololearn: Learn to code for FREE!
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 ๐Ÿ™

9th Apr 2018, 10:59 AM
Raaja Thalapathy
Raaja Thalapathy - avatar
4 Answers
+ 9
Modification to @areila's code - var number; while(isNaN(number)){ number = prompt("No.") }
9th Apr 2018, 11:19 AM
Nikhil
Nikhil - avatar
+ 3
var number; while(number.isNan()){ number = prompt(โ€œPlease input a number:โ€) }
9th Apr 2018, 11:09 AM
Ariela
Ariela - avatar
+ 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! ๐Ÿ˜Š๐Ÿ˜Š๐Ÿ™Œ๐Ÿป
9th Apr 2018, 11:17 AM
Raaja Thalapathy
Raaja Thalapathy - avatar
+ 2
@Nikhil, Thanks bro! Itโ€™s working now ๐Ÿ˜๐Ÿ˜๐Ÿ‘Œ๐Ÿป๐Ÿ‘๐Ÿป
9th Apr 2018, 11:23 AM
Raaja Thalapathy
Raaja Thalapathy - avatar