# JavaScript JS method for writing 99 multiplication table

Shang Silicon Valley iron powder 2021-11-25 18:51:03
javascript js method writing multiplication

Method 1 ：

Observe the law ：

Each line of the first number is self increasing 1.

We sent the second number from 1 Start , In turn, increasing 1, Never greater than the previous number .

Every time the preceding number increases , The following number increases by one round .

We can use double for loop , The initial value of the outer layer is set to i,i from 1 Start , To 9 end , Self increasing 1

The inner layer is set from the initial value to j,j from 1 Start , Less than or equal to the outer layer i, Self increasing 1

The code of 99 multiplication table is as follows ：

for (var i = 1;i<=9;i++){

for (var j = 1;j<=i;j++){

document.write(i+'*'+j+'='+(i*j)+'&nbsp ');

}

document.write('<br>');// Line break

}

Method 2 ：

Observe the law ：

The first number is subtracted from each line 1.

We sent the second number from 1 Start , In turn, increasing 1, Never greater than the previous number .

Each time the preceding number is subtracted , The following number increases by one round .

We can use double for loop , The initial value of the outer layer is set to i,i from 1 Start , To 9 end , Self reduction 1

The inner layer is set from the initial value to j,j from 1 Start , Less than or equal to the outer layer i, Self increasing 1

The code is as follows ：

for(var i =9;i>=1;i--){

for(var j = 1;j<=i;j++){

document.write(i+'*'+j+'='+(i*j)+'&nbsp;&nbsp;&nbsp;');

}

document.write('<br>');

}

https://javamana.com/2021/11/20211109101641984E.html