开发者

General Looping question

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?


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.


The user will have 3 chances (i=2, i=3 and i=4).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜