user3392846
user3392846

Reputation: 65

Looping an IF statement

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

Answers (1)

000
000

Reputation: 27227

Use the "while" loop.

var name = prompt("What's your name?");
while (name === '') {
    name = prompt("Try again");
    alert(name);
}

Upvotes: 8

Related Questions