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?" );
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745629911a4637043.html
评论列表(0条)