乘法表1 x 1=1|1 x 2=2|1 x 3=3使用2d数组Javascript



我是Javascript的初学者,需要使用2d数组创建乘法表。结果应为结果应如下所示:1 x 1=1|1 x 2=2|1 x 3=3。我有以下无法修改的变量。有人能帮忙吗?

const n=3;const calc=[];

for (let i = 1; i < n; i++) {
for (let j = 1; j < n; j++) {
}
}console.log(calc);

这就是您想要的吗?

function calc(n){
for (let i = 1; i <= n; i++) {
for (let j = 1; j <= n; j++) {
console.log(`${i} * ${j} = ${i*j}`)
}
}
}
calc(3)

最新更新