打印九九乘法表
- 首先理解输出9*9的方阵
<script>
for (let q = 1; q <= 9; q++) {
for (let i = 1; i <= 9; i++) {
document.write('# ');
}
document.write('<br>')
}
</script>
- 然后理解输出直角三角形
<script>
for (let i = 1; i <= 9; i++) {
for (let j = 1; j <= i; j++) { //important!!重点在于理解j<=i
document.write(' # ');
}
document.write('<br>');
}
</script>
- 最后将#替换成算式即可
<script>
for (let i = 1; i <= 9; i++) {
for (let q = 1; q <= i; q++) {
document.write(q + ' * ' + i + ' = ' + (i * q) + " ");
}
document.write('<br>')
}
</script>
标签:输出,九九乘法,算式,替换成,理解,let
From: https://www.cnblogs.com/zerotwo-zrx/p/17340665.html