admin管理员组文章数量:1026134
Here is my code. I can't figure out how to stop this loop when the use selects "cancel" from the window.confirm box
I'm really rusty and never delved that deep into programming anywho lol - I am used to C++ so I'm not sure if there just might be a better function to call other than window.confirm.
code:
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 + ", bined they equal: "
+ answer);
window.confirm( "Would you like to go again?" );
if (confirm == true){
askAgain = true;
} else {
askAgain = false;
}
}
Thanks in advance!
Here is my code. I can't figure out how to stop this loop when the use selects "cancel" from the window.confirm box
I'm really rusty and never delved that deep into programming anywho lol - I am used to C++ so I'm not sure if there just might be a better function to call other than window.confirm.
code:
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 + ", bined they equal: "
+ answer);
window.confirm( "Would you like to go again?" );
if (confirm == true){
askAgain = true;
} else {
askAgain = false;
}
}
Thanks in advance!
Share Improve this question edited Jan 25, 2013 at 22:38 MadSkunk 3,7492 gold badges36 silver badges52 bronze badges asked Jan 25, 2013 at 22:21 JpeppaJpeppa 112 silver badges5 bronze badges 2-
Where is the value for
confirm
being assigned? Also, you should be able to merge theaskAgain
andconfirm
variables into a single variable. – Dave Jarvis Commented Jan 25, 2013 at 22:29 - @DaveJarvis It's not, at least not in the code shown here... :) – MadSkunk Commented Jan 25, 2013 at 22:30
1 Answer
Reset to default 5Small error in your code:
while (askAgain = true){
Should be:
while (askAgain == true){
= assigns a value == checks if they are equal
another issue is you need to assign confirm like this:
var confirm = window.confirm( "Would you like to go again?" );
Here is my code. I can't figure out how to stop this loop when the use selects "cancel" from the window.confirm box
I'm really rusty and never delved that deep into programming anywho lol - I am used to C++ so I'm not sure if there just might be a better function to call other than window.confirm.
code:
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 + ", bined they equal: "
+ answer);
window.confirm( "Would you like to go again?" );
if (confirm == true){
askAgain = true;
} else {
askAgain = false;
}
}
Thanks in advance!
Here is my code. I can't figure out how to stop this loop when the use selects "cancel" from the window.confirm box
I'm really rusty and never delved that deep into programming anywho lol - I am used to C++ so I'm not sure if there just might be a better function to call other than window.confirm.
code:
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 + ", bined they equal: "
+ answer);
window.confirm( "Would you like to go again?" );
if (confirm == true){
askAgain = true;
} else {
askAgain = false;
}
}
Thanks in advance!
Share Improve this question edited Jan 25, 2013 at 22:38 MadSkunk 3,7492 gold badges36 silver badges52 bronze badges asked Jan 25, 2013 at 22:21 JpeppaJpeppa 112 silver badges5 bronze badges 2-
Where is the value for
confirm
being assigned? Also, you should be able to merge theaskAgain
andconfirm
variables into a single variable. – Dave Jarvis Commented Jan 25, 2013 at 22:29 - @DaveJarvis It's not, at least not in the code shown here... :) – MadSkunk Commented Jan 25, 2013 at 22:30
1 Answer
Reset to default 5Small error in your code:
while (askAgain = true){
Should be:
while (askAgain == true){
= assigns a value == checks if they are equal
another issue is you need to assign confirm like this:
var confirm = window.confirm( "Would you like to go again?" );
本文标签: javascriptStopping my while loop with a confirm boxStack Overflow
版权声明:本文标题:javascript - Stopping my while loop with a confirm box - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745629909a2160098.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论