Application of the For loop in JavaScript

Source: Internet
Author: User

1. There is a chessboard, there are 64 squares, in the first box to put 1 sesame seed weight is 0.00001kg, the second inside put 2, the third inside put 4, the board on the weight of all sesame

<script>var sum=0;  // The first weight is set at 0;  for (i=1;i<=64;i++) {    var a=1;               // starting at 2 of the 0-time  square     for (j=0;j<i-1;j++)      {        a=a*2;            }    Sum=sum+A;} Alert (0.00001*sum)

2. Badminton racket 15 yuan, ball 3 yuan, water 2 yuan. $200 each at least one, how much could it be

 var  cs=0; //  var  str= ";  for  (i=1;i<=13;i++) //  Each one must have at least one, so start looping from 1  { for  (j=1;j<=66;j++" { for  (N=1;n<=100;n++ =15*i+3*j+2*n;  if  (Sum==200                +=1; STR  +=i+ "Badminton Racket" +j+ "ball" +n+ "bottle of Water" + "| |" }}}}alert (CS) alert (str)  

3 100 or less of 7 related

var str= "";  for (i=0;i<=100;i++) {   if(i%7==0| | i%10==7| | parseint (i%10) ==7)   {      str=str+i+ "| |"    }}alert (str)

Application of the For loop in JavaScript

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.