0

これが私のコードです。ユーザーが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;
    }
}

前もって感謝します!

4

1 に答える 1

5

コードの小さなエラー:

while (askAgain = true){

次のようにする必要があります。

while (askAgain == true){

= 値を割り当てます == それらが等しいかどうかをチェックします

別の問題は、次のように確認を割り当てる必要があることです。

var confirm = window.confirm( "Would you like to go again?" );
于 2013-01-25T22:30:19.143 に答える