こんにちは私はこの関数で問題を抱えていました。数値、開始点、最終点をとり、始点から終点までの数値の乗算表を書く関数を作りたかったのです。例えば、tabmul(10,2,4)は乗算表を返す関数が負の数で失敗します
10.2 = 20
10.3 = 30
10.4 = 40
これは全て良好であるが、それは負の数では動作しないを返します。例えば、 tabmulため(10、-4、-1)を生成する必要があり
10-4 = -40
10-3 = -30
10-2 = -20
10.-1 = -10
ただし、何も返されません。これは私のコードです:
function tabmul(a,b,c){ \\function that generates the multiplication table
var myarray = new Array();
var x
for(x=b; x<=c; x++){
myarray[x - b] = a*x;
document.write(a + "." + x + "=" + myarray[x - b] + "<br>")
}
}
var a = prompt("Enter the number whose table you want to calculate: ","");
var b = prompt("Enter the place where you want the table to start","");
var c = prompt("Enter the place where you want the table to end","");
\\ this checks if the starting point is smaller or equal than the ending point of the table
if (0 <= c-b) {
tabmul(a,b,c);
} else {
alert("The starting point is bigger than the ending point");
}
、および-1(エンドポイント)よりも-4(始点)また、交換する方が良いだろう –
大きいです「」 「x」で表示されます。 ;-) – RobG
そうですか?私は0 <= c-bはb <= cと同じだと思います。開始点は終了点以下です。 –