JS achieves symmetric 9-9 multiplication tables up and down, and js symmetric between left and right
Multiplication tables can be implemented in many languages. This article describes two common types of loops (For and While) in JavaScript to complete these four symmetric 9-9 multiplication tables. This example is a good way to practice loops, because the layout is not neat, a table is circulated.
1. trapezoid multiplication table of degree in the lower left corner:
For Loop code
document.write("<table width='' border='>");for(var i=; i<=; i++){document.write("<tr>");for(var j=; j<=i; j++){document.write("<td>"+ j +"*"+ i +"="+ i*j +"</td>");}document.write("</tr>");}document.write("</table>");
While loop code
document.write("<table width='' border='>");var i = ;while(i<=){document.write("<tr>");var j = ;while(j<=i){document.write("<td>"+ j +"*"+ i +"="+ i*j +"</td>");j++;}document.write("</tr>");i++;}document.write("</table>");
Example
2. The lower right corner is the trapezoid multiplication table of degrees:
For Loop code
document.write("<table width='' border='>");for(var i=; i<=; i++){document.write("<tr>");for(var n=i; n<; n++){document.write("<td> </td>");}for(var j=i; j>=; j--){document.write("<td>"+ j +"*"+ i +"="+ i*j +"</td>");}document.write("</tr>");}document.write("</table>");
While loop code
document.write("<table width='' border='>");var i = ;while(i<=){document.write("<tr>");var n = i;while(n<){document.write("<td> </td>");n++;}var j = i;while(j>=){document.write("<td>"+ j +"*"+ i +"="+ i*j +"</td>");j--;}document.write("</tr>");i++;}document.write("</table>");
Example
3. trapezoid multiplication table of degree in the upper left corner:
For Loop code
document.write("<table width='' border='>");for(var i=; i>=; i--){document.write("<tr>");for(var j=; j<=i; j++){document.write("<td>"+ j +"*"+ i +"="+ i*j +"</td>");}document.write("</tr>");}document.write("</table>");
While loop code
document.write("<table width='' border='>");var i = ;while(i>=){document.write("<tr>");var j = ;while(j<=i){document.write("<td>"+ j +"*"+ i +"="+ i*j +"</td>");j++;}document.write("</tr>");i--;}document.write("</table>");
Example
4. trapezoid multiplication table of degree in the upper right corner:
For Loop code
document.write("<table width='' border='>");for(var i=; i>=; i--){document.write("<tr>");for(var j=; j>=i; j--){document.write("<td> </td>");}for(var j=i; j>=; j--){document.write("<td>"+ j +"*"+ i +"="+ i*j +"</td>");}document.write("</tr>");}document.write("</table>");
While loop code
document.write("<table width='' border='>");var i = ;while(i>=){document.write("<tr>");var j = ;while(j>=i){document.write("<td> </td>");j--;}var j = i;while(j>=){document.write("<td>"+ j +"*"+ i +"="+ i*j +"</td>");j--;}document.write("</tr>");i--;}document.write("</table>");
Example
The above content is the common two types of loops (For and While) in JavaScript used in this article to complete these four symmetric 9-9 multiplication tables. I hope this will help you!
Articles you may be interested in:
- 9. Multiplication Table batch Edition
- Code for the 9-9 multiplication table implemented by javascript and jquery respectively
- For Loop continuous summation, 9-9 multiplication table code
- A small example of Java's 9-9 multiplication table
- Java 9-9 multiplication table example
- PHP outputs a code example of a multiplication table
- SQL statements implement four types of 9-9 multiplication tables