这是我的代码。当用户从 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;
}
}
提前致谢!