JS achieves symmetric 9-9 multiplication tables up and down, and js symmetric between left and right

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.