Reputation: 65
Is there a way to loop an "if" statement using javascript/jquery, example
var name = prompt("What's your name?");
if (name === '') {
name = prompt("Try again");
alert(name);
}
using the code above, it would check once but then whatever the second answer is, it won't check, is there a way to make it check repetitively without writing the if statement a billion times...?
Upvotes: 0
Views: 94
Reputation: 27227
Use the "while" loop.
var name = prompt("What's your name?");
while (name === '') {
name = prompt("Try again");
alert(name);
}
Upvotes: 8