0

这是我的代码。当用户从 window.confirm 框中选择“取消”时,我无法弄清楚如何停止此循环

我真的很生疏,从来没有深入研究过任何人的编程哈哈——我已经习惯了 C++,所以我不确定除了 window.confirm 之外是否还有更好的函数可以调用。

代码:

alert( "1 = 10, 2 = 20, 3 = 30, 4 = 40, 5 = 50" );

var myArray = [0, 10, 20, 30, 40, 50];
var askAgain = true;
var pickOne;
var pickTwo;
var answer;
var numOne;
var numTwo;

while (askAgain = true){

    numOne = prompt( "Select a number by entering the associated slot #:");
    numTwo = prompt( "Select a number to be added to the first number by            

        entering the associated slot #:" );

    pickOne = myArray[numOne];
    pickTwo = myArray[numTwo];

    pickOne.Number;
    pickTwo.Number;

    answer = pickOne + pickTwo;

    alert("You picked " + pickOne + " and " + pickTwo + ", combined they equal: "       

        + answer);

    window.confirm( "Would you like to go again?" );
    if (confirm == true){
        askAgain = true;
    } else {
        askAgain = false;
    }
}

提前致谢!

4

1 回答 1

5

代码中的小错误:

while (askAgain = true){

应该:

while (askAgain == true){

= 赋值 == 检查它们是否相等

另一个问题是您需要像这样分配确认:

var confirm = window.confirm( "Would you like to go again?" );
于 2013-01-25T22:30:19.143 回答