0

私はいくつかの宿題に取り組んでいます、そしてこの最後の問題は私の後ろを蹴ることです、私がそれを実行するたびに、それは入力された情報の最後のループを表示しません。したがって、3つのループに入ると、2つだけが表示されます。

助けてくれてありがとう。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Casino_Eric</title>
    <script type="text/javascript">

        document.write( "<h1>Casino_Eric</h1>" );
        var CashierID, CustomerCount=0, TotalChips, OverAllValue, EndOrContinue;
        var BlueValue = 5, BlackValue = 20, RedValue = 50, GreenValue = 100;
        var BlueQty, BlackQty, RedQty, GreenQty;
        var BlueResult, BlackResult, RedResult, GreenResult;

        CashierID = window.prompt("Enter 6 digit cashier ID.", "000000");
            do{
                BlueQty = window.prompt("Enter Number of Blue Chips", "0");
                BlackQty = window.prompt("Enter Number of Black Chips", "0");
                RedQty = window.prompt("Enter Number of Red Chips", "0");
                GreenQty = window.prompt("Enter Number of Green Chips", "0");

                BlueResult = BlueQty * BlueValue;
                BlackResult = BlackQty * BlackValue;
                RedResult = RedQty * RedValue;
                GreenResult = GreenQty * GreenValue;
                OverAllValue = BlueResult + BlackResult + RedResult + GreenResult;


                EndOrContinue = parseInt(window.prompt("Would you like to end your shift now "+CashierID+" or count the chips for another customer?  Enter 1 to contiue, or N to quit.", "n"));
                    if(isNaN(EndOrContinue));
                    else{
                    CustomerCount++;
                    document.write("<p>Cashier ID: "+CashierID+", Customer : "+CustomerCount+"</br> Number of Blue Chips: "+BlueQty+", total value of Blue Chips is: "+BlueValue+"</br>Number of Black Chips: "+BlackQty+", total value of Black Chips is: "+BlackValue+"</br>Number of Red Chips: "+RedQty+", total value of Red Chips is: "+RedValue+"</br>Number of Green Chips: "+GreenQty+", total value of Green Chips is: "+GreenValue+"</br>This customer's total value is "+OverAllValue+".</p>");

                    }
                }
            while(!isNaN(EndOrContinue));


        </script>
    </head>
    <body>  
        <p>Reload for another conversion</p>
    </body>
</html>
4

2 に答える 2

1

if文の書き間違いが原因でした。今、それはあなたのためにうまくいくでしょう

 <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Casino_Eric</title>
        <script type="text/javascript">

            document.write( "<h1>Casino_Eric</h1>" );
            var CashierID, CustomerCount=0, TotalChips, OverAllValue, EndOrContinue;
            var BlueValue = 5, BlackValue = 20, RedValue = 50, GreenValue = 100;
            var BlueQty, BlackQty, RedQty, GreenQty;
            var BlueResult, BlackResult, RedResult, GreenResult;

            CashierID = window.prompt("Enter 6 digit cashier ID.", "000000");
                do{
                    BlueQty = window.prompt("Enter Number of Blue Chips", "0");
                    BlackQty = window.prompt("Enter Number of Black Chips", "0");
                    RedQty = window.prompt("Enter Number of Red Chips", "0");
                    GreenQty = window.prompt("Enter Number of Green Chips", "0");

                    BlueResult = BlueQty * BlueValue;
                    BlackResult = BlackQty * BlackValue;
                    RedResult = RedQty * RedValue;
                    GreenResult = GreenQty * GreenValue;
                    OverAllValue = BlueResult + BlackResult + RedResult + GreenResult;

                        document.write("<p>Cashier ID: "+CashierID+", Customer : "+CustomerCount+"</br> Number of Blue Chips: "+BlueQty+", total value of Blue Chips is: "+BlueValue+"</br>Number of Black Chips: "+BlackQty+", total value of Black Chips is: "+BlackValue+"</br>Number of Red Chips: "+RedQty+", total value of Red Chips is: "+RedValue+"</br>Number of Green Chips: "+GreenQty+", total value of Green Chips is: "+GreenValue+"</br>This customer's total value is "+OverAllValue+".</p>");


                    EndOrContinue = parseInt(window.prompt("Would you like to end your shift now "+CashierID+" or count the chips for another customer?  Enter 1 to contiue, or N to quit.", "n"));
                        if(!isNaN(EndOrContinue)){
                        CustomerCount++;
                        }
                    }while(!isNaN(EndOrContinue));


            </script>
        </head>
        <body>  
            <p>Reload for another conversion</p>
        </body>
    </html>
于 2013-02-15T14:29:22.167 に答える
0

「宿題」の例/質問として(正直に感謝します)私の答えはその考えに基づいています-あなたは自分の仕事をしなければなりませんが、これは役立つはずです:

 EndOrContinue = parseInt(window.prompt("Would you like to end your shift now "+CashierID+" or count the chips for another customer?  Enter 1 to contiue, or N to quit.", "n"));
                    if(isNaN(EndOrContinue));
                    else{
                    CustomerCount++;
                    document.write("<p>Cashier ID: "+CashierID+", Customer : "+CustomerCount+"</br> Number of Blue Chips: "+BlueQty+", total value of Blue Chips is: "+BlueValue+"</br>Number of Black Chips: "+BlackQty+", total value of Black Chips is: "+BlackValue+"</br>Number of Red Chips: "+RedQty+", total value of Red Chips is: "+RedValue+"</br>Number of Green Chips: "+GreenQty+", total value of Green Chips is: "+GreenValue+"</br>This customer's total value is "+OverAllValue+".</p>");

                    }
                }
            while(!isNaN(EndOrContinue));

ここでは、質問に基づいて値を設定します - わかりました。

  • 次に、前のエントリで何かを行う前に、質問から設定された値を確認します
  • 次に、それらの以前のエントリで行う必要があることを忘れる (スキップする)
  • 次に、質問の回答を確認します(再度)

初めて(ループ内で)チェックするのはなぜですか?それを削除できますか?

于 2013-02-15T14:28:42.390 に答える