JS Control Statement Exercise (review)

Source: Internet
Author: User

1, a small ball from 100 meters in the air, each rebound half height, the total number of balls through the meter, what is the 10th rebound height?

//define the initial drop process heightvarsum1= 0;//define the initial ascent heightvarsum2= 0;//Height Changevarhight= 100; for(vari=0;i<10;i++){//Drop Changesum1+=hight; Hight=HIGHT/2;if(i<9){//Rise Changesum2=sum2+hight; }}alert (Sum1+SUM2);//Total Distancealert (hight);//Tenth rebound Height

2.

The bonuses awarded by the Enterprise are based on the profit percentage.
If the profit (I) is less than or equal to $100,000, the bonus may be raised by 10%;
Higher than 100,000 yuan, less than 200,000 yuan, less than 100,000 yuan in part by 10% commission, higher than the portion of 100,000 yuan, can commission 7.5%;
Between 200,000 and 400,000, higher than 200,000 yuan of the portion, can commission 5%;
400,000 to 600,000 is higher than the portion of 400,000 yuan, can commission 3%;
Between 600,000 and 1 million, higher than 600,000 yuan of the portion, can commission 1.5%, higher than 1 million yuan, the portion of more than 1 million yuan by 1% Commission,
Enter the current month profit I from the keyboard, the total bonus should be issued?

SUM1 = 0.1 * 10; sum2= Sum1 + 0.075 * (20-10); Sum3= sum2 + 0.05 * (40-20); Sum4= sum3 + 0.03 * (60-40); SUM5= Sum4 + 0.015 * (100-60);//Define total Commission variablesvari;varSum=parseint (Prompt ("Please enter monthly Profit/Wan Yuan"));if(Sum < 0) {alert ("Waiting for bankruptcy.");}Else if(Sum > 0 && sum <= 10) {i==0.1 *sum;}Else if(Sum > Ten && sum <= 20) {i==SUM1 + 0.075 * (sum-10);}Else if(Sum > && sum <= 40) {i==SUM2 + 0.05 * (sum-20);}Else if(Sum > Max && sum <= 60) {i==SUM3 + 0.03 * (sum-40);}Else if(Sum > && sum <= 100) {i==SUM4 + 0.015 * (sum-60);}Else{i==SUM5 + 0.01 * (sum-100);} alert (i);//Total Bonuses

3, 9x9 multiplication formula output

// row definition  for (var i=1;i<=9;i++) {    for (var j=1;j<=9;j++) {        if (i<=j) {            document.write (i+ "x" +j+ "=" +i*j);        }    }    document.write ("<br>");}

4, the input array, the largest exchange position with the first element, the smallest and the last element exchange position, the output array.

varStr=prompt (' Input a string array '));varArr=str.split (', '); varMAX=ARR[0];//define the maximum valuevarMIN=ARR[0];//Define minimum valuevarmaxsum=0;//Max Subscriptvarminsum=0;//Lowest Value subscript//Maximum minimum value found for(vari=0;i<arr.length;i++){    if(Max <=+Arr[i]) {Max=Arr[i]; Maxsum=i; }    if(Min >=+Arr[i]) {min=Arr[i]; Minsum=i; }}//Assignment Exchange LocationArr[maxsum]=arr[0];arr[minsum]=arr[arr.length-1];arr[0]=Max;arr[arr.length-1]=Min;alert (arr); Console.log (arr);

5, there are five students, each student has three achievements, from the keyboard input the above data (including students good, name, three lessons), calculate the average score.

//School NumbervarStudent_id=[];//namevarName_id=[];//AchievementsvarResult_id=[[],[],[],[],[]]; for(vari=0;i<5;i++) {Student_id[i]=prompt ("Enter" + (i+1) + "Student Number"); Name_id[i]=prompt ("Enter" + (i+1) + "Name of student");  for(vark=0;k<3;k++) {Result_id[i][k]=prompt ("Input" + (i+1) + "Student's first" + (k+1) + "entrance class results"); }}//Definition LookupvarSum_sum= "";//Traverse for(varh=0;h<5;h++){    varSum=0; Sum_sum+ = "School Number:" +student_id[h]+ "Name:" +Name_id[h];  for(varj=0;j<3;j++) {sum_sum+ = "\ n" + (j+1) + "Door Subject score:" +Result_id[h][j]; Sum+=result_id[h][j]*1; }    varAVG = SUM/3; sum_sum+= "\ n average:" +avg+ "\ n";//Average score}console.log (sum_sum);

6, Badminton racket 15 yuan, the ball 3 yuan, the water two yuan. 200 USD at least one of each, how many possibilities there are.

var sum=0;  for (var a=1;a<51;a++) {    for (var b=1;b<101;b++) {        for (var c=1;c<201;c++) {            if(a*2+b*1+c*0.5==100 && a+b+c==100 ) {                sum+ +;                Console.log ("All the situation is Rooster" +a+ "only, hen" +b+ "only, Chick" +c+ "only")     }}}

7, Rooster 2, hen 1, chicken half-text, each of at least one, 100 to buy 100 chickens how many kinds of possible?

var sum=0;  for (var a=1;a<51;a++) {    for (var b=1;b<101;b++) {        for (var c=1;c<201;c++) {            if(a*2+b*1+c*0.5==100 && a+b+c==100 ) {                sum+ +;                Console.log ("All the situation is Rooster" +a+ "only, hen" +b+ "only, Chick" +c+ "only")     }}}

8, there is a 0.0001 meters of paper, fold more than the last can reach the height of Mount Everest 8848 meters.

var a=0.0001;  for (var i=1;i>=1;i++) {    = a*2;     if (a>8848) {        break;    }} Alert ("The total needs to be folded" +i+ "Times");

JS Control Statement Exercise (review)

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.