Web Basics Learning JS, cycling practice

Source: Internet
Author: User




1. Judging leap years


var i;
for (i=1980;i<=2016;i++)
{
  if (i% 4 = 0 && i%!= 0 | | i% = = 0)
  document.write (i + "");
}



2.99 Multiplication Table


var i, J;
for (i=0;i<10;i++)
{for
  (j=1;j<=i;j++) {
    document.write (i + "*" + j + "=" +i*j);
    document.write ("  ");
  }
document.write ("<br/>");
}




A 3.100-999 Narcissus:


The first method:

var i,a = 0,b =0,c = 0;
for (i = 100;i < 1000;i++) {
   a = parseint (i/100);
   b = parseint (I/10-a *);//b = parseint (i/%100/10);
   c = parseint (i%);
  if (i== (A * a * a + b * b * b + c * c * c))
document.write (i + "");
}


The second method:
for (var i = 1;i < 10;i++) {for
     (var j = 0;j < 10;j++) {for
        (var k=0; k < 10;k++) {
           if (i * + J * 10 + k = i * I * i + J * J * j + K * k * k) {
           document.write (i * + J * + K + "");}}}



4.1+3+5+7.......+99


var i,sum=0;
document.write ("The result of 1+3+5+7.......+99 is:");
for (i = 0;i < 100;i++) {
   if (i% 2!= 0) {
   sum+=i;
   }
}
document.write (sum+ "");



Factorial within 5.100.


var i,sum=1;
document.write ("the factorial result within 100 is:");
for (i = 1;i <= 100;i++) {
   sum*=i;
}
document.write (sum+ "");



6. Print Triangle


for (var i = 0; i < 6; i++) {for
   (var j = 0; J < 5-i; j) {
       document.write ("");
   }
   for (var j = 0; J < i; J +) {
      document.write ("*");
   }
document.write ("<br/>");

}


7. Diamond


for (var i = 0; i < 6; i++) {for
     (var j = 0; J < 5-i; j) {
        document.write ("");
     }
     for (var j = 0; J < 2*i+1; J + +) {
        document.write ("*");
     }
document.write ("<br/>");

}
for (var i = 0; i < 5; i++) {for
    (var j = 0; J < i+1;j++) {
       document.write ("");
    }
    for (var j = 0; J < 2* (4-i)-1 J + +) {
        document.write ("*");
    }
document.write ("<br/>");

}


8. Empty Diamond


for (var i = 0; i < 6; i++) {for
   (var j = 0; J < 5-i; j) {
      document.write ("");
   }
   for (var j = 0; J < 2 * i + 1; j + +) {
     if (j = = 0 | | j = = 2 * i)
        document.write ("*");
     else{
     document.write ("");
     }
   }
document.write ("<br/>");

}
for (var i = 0; i < 5; i++) {for
    (var j = 0; J < i + 1;j++) {
      document.write ("");
    }
    for (var j = 0; J < 2 * (4-i)-1 J + +) {
      if (j = = 0 | | j = = 2 * (4-i)-2)
          document.write ("*");
     else{
         document.write ("");
      }
     }
document.write ("<br/>");
}


9. Judging today is the day of the week


var now = new Date ();
var day = Now.getday ();
var str = ""; Switch (day) {<span style= "White-space:pre" > </span>case 1: <span style= "White-space:pre" > </span
>str = "Monday";
<span style= "White-space:pre" > </span>break; <span style= "White-space:pre" > </span>case 2: <span style= "White-space:pre" > </span>str = "Tuesday
";
<span style= "White-space:pre" > </span>break; <span style= "White-space:pre" > </span>case 3: <span style= "White-space:pre" > </span>str = "Wednesday
";
<span style= "White-space:pre" > </span>break; <span style= "White-space:pre" > </span>case 4: <span style= "White-space:pre" > </span>str = "Thursday
";
<span style= "White-space:pre" > </span>break; <span style= "White-space:pre" > </span>case 5: <span style= "White-space:pre" > </span>str = "Friday
";
<span style= "White-space:pre" > </span>break; <span style= "White-spacE:pre "> </span>case 6: <span style=" White-space:pre "> </span>str =" Saturday ";
<span style= "White-space:pre" > </span>break; <span style= "White-space:pre" > </span>case 7: <span style= "White-space:pre" > </span>str = "Sunday
";
<span style= "White-space:pre" > </span>break; } document.write ("Today is:" + str);



10. The Air triangle


for (var i = 0; i < 6; i++) {for
    (var j = 0; J < 5-i; j) {
       document.write ("");
    }
    for (var j = 0; J < 2 * i + 1; j + +) {
        if (j = = 0 | | j = = 2 * i)
           document.write ("*");
<span style= "White-space:pre" >	</span>else{
<span style= "White-space:pre" >	</ span>    document.write ("");
<span style= "White-space:pre" >	</span>}
document.write ("<br/>");
<span style= "White-space:pre" >	</span>if (i = 5)
<span style= "White-space:pre" >	</span>{
<span style= "White-space:pre" >	</span>for (var j = 0; J < 2 * i + 1; j + +)
&L T;span style= "White-space:pre" >	</span>document.write ("*");
        }






11.1-1/2+1/3-1/4+........-1/100 = 1+ ( -1/2) +1/3+ ( -1/4) ... + ( -1/100)
var sum = 0;
for (var i = 1;i <= i++) {
  if (i% 2 = 0) {
<span style= "White-space:pre" >	</span>sum = sum + -1 * (1/i);
   }
  else {
    sum = sum + 1/i;
  }
}
document.write (sum);







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.