Reputation: 845
var answer = " ";
var correct = "4";
var question = "What is 2 * 2?";
for(i = 2; i < 5; i++) {
answer = prompt(question, "0");
if (answer == correct) {
alert("Your answer is correct!");
break;
}
}
How many chances would the user have before the break command got executed?
Upvotes: 0
Views: 95
Reputation: 347216
The user would have 3 chances unless they guessed right on the 1st or 2nd chance. Then they would only have 1 or 2 chances respectively.
i = 2 in the first iteration, i = 3 in the next iteration and i = 4 in the last iteration. Before another iteration starts i is set to 5 and the condition fails.
Upvotes: 4