The JS exercises I've done before

Source: Internet
Author: User
Tags soap ming

1. The horse carries 2 stone grain, the middle horse carries 1 stone grain, the two ponies carry one stone grain, must use 100 horses, carries 100 stone grain, how to deploy?

 for (var i=0;i<=50;i++) {  for (var a=0;a<=100;a++) {   for ( var b=0;b<=100;b++) {
Do three cycles, which are the number of small and medium-size horses if((i*2+a+b/2==100) && (i+a+b==100)) {
To make a judgment, the horse x2+ (1) + Pony/2 of the number of 100, and three stud number added up equals to document.write ("Big" +i+ "+a+" small "+b+" <br/> ");
Output}}}


2.6. A reconnaissance team received an urgent task requiring as many as possible a number of persons in A, B, C, D, E and F six players, subject to the following limitations
Conditions:
A and B at least one person;
A and D cannot go together;
A, E and F three shall send two men;
B and C neither go nor go;
C and D two to one;
If D does not go, then E will not go.
How many people should I ask for?

 for(vard1=0;d1<=1;d1++){     for(vard2=0;d2<=1;d2++){         for(vard3=0;d3<=1;d3++){             for(vard4=0;d4<=1;d4++){                 for(vard5=0;d5<=1;d5++){                     for(vard6=0;d6<=1;d6++){
For six players to cycle, go for 1, not go for 0if(d1+d2>=1) && (d1+d4<=1) &&(D1+d5+d6==2) && (d2==d3) && (d3+d4==1) && (d4==d5)) {
Write judgment according to condition document.write (D1+ "+d2+" "+d3+" "+d4+" "+d5+" "+d6+" <br/> ");
Output }}}}}

3. There is a monkey and a bunch of peaches in the park, and the monkeys eat half of the peaches every day and throw away a bad one in half. To the seventh day of
, the monkey opened his eyes and found only a peach left. Q. How many peaches are there in the park at first?

var d=1;  for (var t=1;t<=6;t++) {
Six-day cycle D= (d+1) * *;
Plus a daily throw of the bad multiplied by the second return to the original Peach}document.write ("The first day there is a" +d+ "peach <br>");
Output results


4. Print with shape:







 for (var i=1;i<=7;i++) {    for (var w=1;w<=8;w++) {
Let 's do 7 cycles, eight points a line at a time
document.write ("");
document.write ("<br/>");
}
}





for (Var i=1;i<=5;i++) {
for (Var q=1;q<=i;q++) {

Do 5 cycles, and the number of cycles in each cycle is equal to this number of times
document.write ("");
}
document.write ("<br/>");
}





 for (var i=1;i<=5;i++) {    for (var q=i;q<=5;q++) {
Do 5 cycles, similar to the previous one, here in turn with document.write (""); }
document.write ("<br/>");}


---
--
-

 for (var i=5;i>=1;i--) {    for (var q=1;q<=5;q++) {        if (q<i) {            document.write ("-");        }     Else {            document.write ("");        }  
}
Do 5 cycles, then add a judgment inside.
document.write ("<br/>");
}

5.1. Xiao Ming unit sent 100 yuan of shopping card, Xiao Ming to the supermarket to buy three types of washing supplies, shampoo (15 yuan), Soap (2 Yuan), toothbrush (5 yuan
)。 To spend 100 yuan good, but if you have a combination of purchase?

 for (var i=0;i<=7;i++) {    for (var q=0;q<=50;q++) {        for (var w=0;w<=20;w++) {        if(i*15+q*2+w*5==100) {
After the cycle according to the conditions to make a judgment document.write ("shampoo" +i+ "Money:" +i*15+ "soap" +q+ "Money:" +q*2+ " toothbrush " +w+ "Money:" +w*5+ "<br /> "); }}}


6. Five children lined up in a team. Ask the first how old, the first to say two years older than the second, ask the second, the second one is two years older than the third one.
And so on Ask the fifth child how old, the fifth child said 3 years old. Q How old is the first child?

var a=3;  for (var i=4;i>=1;i--) {var a=a+2;}
The condition in turn makes the formula, looping according to the number of times
document.write ("The Last Child:" +a+ "old");

7.99 Multiplication Table

document.write ("<table>");
Table for (var i=9;i>=1;i--) { document.write ("<tr>"); for (var a=1;a<=i;a++) {
Cycle according to the number of times, and then connect up document.write ("<td>"); document.write (a+ "x" +i+ "=" +a*i); document.write ("</td>"); } document.write ("</tr>");}
document.write ("</table>");



8. Print out all the "daffodils", the so-called "Narcissus number" refers to a three-digit number, whose numbers are cubic and equal to the number itself.
For example: 153 is a "narcissus number", because the 153=1 three times the square +5 of the three +3 Times Square.

 for (var a=1;a<=9;a++) {    for (var b=0;b<=9;b++) {        for  (var c=0;c<=9;c++) {            if (a*a*a+b*b*b+c*c*c==a+ "" +b+ "" +c) {
Make three numbers, then compare document.write (a+ "" +b+ "" +c+ "<br>") with the three numbers connected when the condition is met. }}

9. There are a pair of young rabbits, 1 months after the young rabbit into a rabbit, the rabbit 1 months later into a rabbit and gave birth to a pair of rabbits, asked how many years later on rabbits, young
What are the logarithm of rabbits, rabbits and Cheng?

varDa=0;varZh=0;varXi=1;varZo=1;  for(varq=1;q<=12;q++){        if(q==1) {da=1; ZH=0; Xi=0; Zo=1; document.write ("Big" +da+ "+zh+" small "+xi+" altogether "+zo+" <br> "); }    Else{da=zh+da; ZH=XI; Xi=da; Zo=zh+xi+da; document.write ("Big" +da+ "+zh+" small "+xi+" altogether "+zo+" <br> "); }}
According to the conditions of the rabbit, the first assignment, and then from the second start of the law and then give the formula loop

10. How many possibilities do you have to chip in and 1,2,5 20 yuan of money?

 for (var rd=0;rd<=20;rd++) {    for (var ld=0;ld<=20;ld++) {           for (var gd=0;gd<=20;gd++) {            if(rd*1+gd*2+ld*5==20) {
In the loop to write a judgment, meet the 20-dollar condition after the output document.write ("A Piece ofmoney:" +rd+ "two dollars:" +gd+ "five dollars:" +ld+ "<br>");}} }

11. Sum of Hundred

var number=0;    for (var i=1;i<=100;i++) {
Loop out 1 to 100 and add up to assign value number=number+i;} document.write (number);

12. Base Sum

var number2=0;      for (var i=1;i<=100;i+=2) {
Loop out the cardinality from 1 to 100 and add up the assignment
number2=number2+

document.write (NUMBER2);

13. Even sums

var number3=0;      for (var i=2;i<=100;i+=2) {
Loop out the even number in 1 to 100 and add up the assignment
Number3=number3+

document.write (NUMBER3);


14. A total of 100 chickens, cocks 5 yuan 1, hen 3 yuan 1, chicken 1 yuan 3, buy 100 chickens, what are the ways?

 for (x=0;x<=20;x++) {    for (y=0;y<=40;y++) {        for (z=0;z<=100;z++ ) {            if((x*5+y*3+z/3==100) && (x+y+z==100)) {
After circulating out three kinds of chickens, according to the condition, the price equals 100 and the quantity equals 100.
document.write ("Rooster" +x+ "hen" +y+ "chick" +z+ "<br/>"); }}}

The JS exercises I've done before

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.