JavaScript applet--using nested loops to output multiplication tables

Source: Internet
Author: User
In the process of learning JavaScript, the first time to contact the loop statement when the multiplication table to practiced hand, here I will be my practice posted here, I hope to give the same beginners and I a little help, but also hope that the great God can feel free. First of all, take a look at the multiplication table what it looks like, do not tell me that everyone can remember clearly oh! Secondly, the multiplication table is a table, there are rows and columns, using nested loops to output the inevitable use of two parameters, with I for the line number, J for the column number. In addition, we look at the entire table as a string, so we set the string to Res. The code is as follows: var res = "", i,j; then, loop through the line number and loop through the column number in the line number loop. for (i=1;i<=9;i++) {//j<=i will not be stepped output, if it is j<=9, then the output is 9x9 rectangle table for (j=1;j<=i;j++) {res + = i + "x" + j + "=" + I*j + "& ; nbsp&nbsp&nbsp ";} NewLine res + = "<br>";} Finally, output res to the HTML document with the following code: document.getElementById ("Div01"). InnerHTML = res; all codes are as follows: <body><div id= "DIV01" > </div><script>var res = "", I,j;for (i=1;i<=9;i++) {for (j=1;j<=i;j++) {res + = i + "x" + j + "=" + i*j + "&nbsp&nbsp&nbsp";} Res + = "<br>";} document.getElementById ("Div01"). InnerHTML = res;</script></body> The code and explanation of the multiplication table using JavaScript output is the above, The first time to write this summary, some do not know what to write the feeling, the wrong place please forgive and feel free.

JavaScript applet--using nested loops to output 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.