About the practice of using the For loop to solve practical problems in JS

Source: Internet
Author: User

First question:
X3 * 6528 = 3X * 8256
X fills in a number for a number to make the equation set

for (x=1;x<10;x++) {
var a= (x*10+3);
var b= (3*10+x);
if (a*6528==b*8256) {
alert (x);
}
}
The second question:
On the page, output the shape
*
***
*****
*******
*********

var x = 1;
for (Var i=4;i>=0;i--) {

for (var sp = 1;sp<=i;sp++) {
document.write ("&nbsp;");
}
for (var st = 1;st<=x;st++) {
document.write ("*");
}

x+=2;
document.write ("<br>");
}

Question three:
Find out all the "daffodils" between 100-999. The so-called Narcissus number refers to a three-digit number, the cubic of the numbers and equal to the number itself. (such as 15 of the 3-time Square =1 of 3 square +5 3 times Square +3) and output these numbers
for (x=1;x<10;x++) {
for (y=1;y<10;y++) {
for (z=1;z<10;z++) {
M=x*x*x+y*y*y+z*z*z;
N=100*x+10*y+z;
if (m==n) {
document.write (n+ "<br>");
}
}
}
}
Question Fourth:
Output all leap years from 1000 to now
for (var sb = $; SB <=; sb++) {
if (sb% 100 = 0) {
if (sb% 4 = = 0 && SB% 100! = 0) {
document.write (SB + "<br>");
}
} else {
If (sb% 400 = = 0) {
document.write (SB + "<br>");
}
}
}

Question Fifth:
Write programs, calculate 1!+2!+3!+.....+10! The result.

var x=0;

for (i=1;i<11;i++) {
var a=1;
for (b=1;b<=i;b++) {
A*=b;
}
X+=a;
}
alert (x);

About the practice of using the For loop to solve practical problems in JS

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.