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 the askAgain and confirm 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
Add a ment  | 

1 Answer 1

Reset to default 5

Small 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 the askAgain and confirm 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
Add a ment  | 

1 Answer 1

Reset to default 5

Small 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