您需要有两个循环 - 一个嵌套在另一个循环内 - 都从 1 到 10。就像是:for (let i = 1; i <= 10; i++) { for (let j = 1; j <= 10; j++) { let s = i * j; document.write(i + "*" + j + "=" + s + "<br>"); }}或者,允许用户输入他们选择的数字:let a = prompt("Enter a number: ");if (a) { for (let i = 1; i <= 10; i++) { let b = i * a; document.write(a + "*" + i + "=" + b + "<br>"); }}
var a;var b; for (var a = 1; a <= 10 ; a++) { // loop the a number 1 to 10 for (var i = 1; i <= 10 ; i++) { b = a * i; document.write(" " +a+ "*", + b + "<br>"); }}