2013-02-15 17 views
0

我正在做一些家庭作業,這最後一個問題是踢我的後方,每次我運行它,它不顯示輸入信息的最後一個循環。因此輸入3個循環,只顯示2個循環。javascript做,而不是寫最後一個循環

感謝您的幫助。

<!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> 
+3

此行'如果(isNaN(EndOrContinue));'在底部看起來我錯了,然後尤其是當用'else' – MildlySerious 2013-02-15 14:11:50

+0

這一部分:'如果(isNaN( EndOrContinue));'真的很奇怪,應該修改。 – Sebas 2013-02-15 14:13:51

+0

@MildlyInteresting,是的,它應該是'if(!isNaN ....){做這些事情....',而不是忽略正面檢查和使用其他邏輯倒置 – 2013-02-15 14:14:00

回答

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)); 

這裏你根據一個問題設置價值 - 在那裏。

  • 然後你前檢查值從問題設置你做任何事情與以前的條目
  • 然後你忘了(跳過)做你需要與以前的條目做
  • 那麼你檢查問題的反應(再次)

爲什麼你甚至檢查第一次(在你的循環)?你可以刪除嗎?

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>