我努力使產生的數學表的任何數量的像這樣的程序:發行與製作數量的表項目(如12×1 = 12)在Javascript
3×1 = 3
3 ×2 = 6
3×3 = 9
3×4 = 12
我需要用戶輸入:
(1)它們需要(例如 - 3)表中的所有數
(2)指定開始點(例如 - 1)
(3)指定的結束點(例如 - 4)
我有缺陷的代碼到目前爲止如下:
function isitanumber(numb){
while (isNaN(numb) == true){
\t \t numb = parseInt(prompt("Please add a valid number","5"));
\t }
}
function mytable (thenum, first, second){
for (var i=first; i<=second; i++){
\t var y = thenum*i;
\t document.write(thenum + " x " + i + " = " + y + "</br>");
}
}
var mynum = parseInt(prompt("Enter the number you wish to have the table for", "40"));
mynum = isitanumber(mynum);
var startpoint = parseInt(prompt("Enter the startpoint of the table", "1"));
mynum = isitanumber(startpoint);
var endpoint = parseInt(prompt("Enter the endpoint of the table", "10"));
mynum = isitanumber(endpoint);
mytable(mynum,startpoint,endpoint);
什麼問題? – SLaks
每當我在第一個提示中輸入字母,然後在第二個提示中輸入數字,它就會給我NaN。具體來說,我需要找出如何訪問用戶輸入的最後一個值,其中isNaN爲false。 – nishkaush
使用調試器來查看你的變量是什麼。 – SLaks