2011-04-18 136 views
1

我想讓用戶輸入一個數字,然後輸入另一個數字,該數字將開始輸入第一個數字的乘法表,並繼續遞增1,直到達到用戶提示的最後一個數字...Javascript函數問題

例如,如果用戶是要輸入10,則如圖1所示,然後如圖10所示,輸出將如下所示:

10 * 1 = 10
10 * 2 = 20
10 * 3 = 30
...
10 * 10 = 100


我在做什麼錯?

感謝您的幫助!

function multiplierz(numberMultiplied, amountToMultiplyFirst, amountToMultiplyLast) 
    { 


     while (isNaN(numberMultiplied) = true || isNaN(amountToMultiplyFirst) = true || isNaN(amountToMultiplyLast) = true) 
     { 
      alert("YOU DID NOT ENTER ONLY NUMBERS. WAY TO GO DUMMY."); 
      var numberMultiplied = prompt("Please Enter The Number to Multiply"); 
      var amountToMultiplyFirst = prompt("Start multiplying by which number?"); 
      var amountToMultiplyLast = prompt("End multiplying by which number?"); 
     } 
     for (counter = amountToMultiplyFirst; counter <= amountToMultiplyLast; counter++) 
      { 
       document.write(numberMultiplied + " * " + counter + " = " + numberMultiplied * counter + "<br />"); 
      } 
    } 

    //Begin Program Below 


     multiplierz(prompt("Please Enter The Number to Multiply"),prompt("Start multiplying by which number?"),prompt("End multiplying by which number?")); 
</script> 
+2

+1快訊的 – Brad 2011-04-18 04:07:02

+0

什麼問題? – 2011-04-18 04:08:36

+0

它不運行:P – bruchowski 2011-04-18 04:10:26

回答

2

你需要在你的while條件使用==,而不是=

while (isNaN(numberMultiplied) == true || isNaN(amountToMultiplyFirst) == true || isNaN(amountToMultiplyLast) == true) 
{ 
    ... 
} 
0

,你沒有考慮amountToMultiplyFirst簡單的事情應該比amountToMultiplyLast少:-)

4

isNan(numberMultiplied) = true拋出一個錯誤。在JavaScript中,=運算符用於分配。

只是做

while (isNaN(numberMultiplied) || isNaN(amountToMultiplyFirst) || isNaN(amountToMultiplyLast))