用确认框停止我的 while 循环
Stopping my while loop with a confirm box
这是我的代码。 我无法弄清楚当使用从窗口中选择"取消"时如何停止此循环。
我真的很生疏,从来没有深入研究过编程,哈哈 - 我习惯C++所以我不确定除了 window.conconfirm 之外是否有更好的函数可以调用。
法典:
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;
}
}
提前感谢!
代码中的小错误:
while (askAgain = true){
应该是:
while (askAgain == true){
= 赋值== 检查它们是否相等
另一个问题是您需要像这样分配确认:
var confirm = window.confirm( "Would you like to go again?" );
相关文章:
- 为什么不't Javascript对我的输入值进行了一些重新检查
- 可以't让我的if语句处理js中的html表单输入
- 我的单元测试选项是什么
- 将输入字段中的文本提交到我的数据库,同时将其添加到我的列表中
- 我的职位回报太快了,如何做出承诺
- 我的jQuery插件参数没有正确启动,遇到了问题
- 为什么我的While循环不起作用
- 为什么我的 while 循环没有完全迭代
- 我需要找到素数索引,但我的 while 循环正在退出
- 为什么我的while循环是无限的?每次都更改变量,但条件仍然始终为真
- 为什么获胜'我的While Loop工作
- 我的do while循环陷入了无限循环
- 试着写一个do-while循环语句来打印我的语句,但是它目前没有打印它
- 为什么我的javascript不在这个while循环中改变bg的颜色?
- 我如何在javascript中创建一个有许多条件的while循环
- 初学者:试图用do while循环来实现我的想法,把我的头弄破了
- 我的while循环是'不工作
- Javascript-我的setTimeOut在while循环中没有'不起作用
- 用确认框停止我的 while 循环
- (JS)为什么我的While循环不工作!也许我不理解这个基本概念