当前位置:网站首页>JS small exercise

JS small exercise

2022-07-07 07:14:00 Luqi zz

Catalog

1. The user enters a number , Determine whether the number is odd or even , If it is not a number, you should also give a prompt

2. Determine the maximum value between two numbers ( The user enters two numbers , Determine which number is larger )

3. Judgment of grade

4. The user enters a year , Determine the number of days in the year

5. Make a study schedule , Enter the day of the week , Can you remind me what courses to learn today

6. The taxi , Start at (2 km ) by 7 element , exceed 2 Kilometers per kilometer 3 Yuan calculation . It is required to calculate the cost according to the distance

7. Judgement of leap year ( The condition of leap year is that it can be 4 to be divisible by , But can't be 100 to be divisible by ; Or can be 400 to be divisible by .)

8. Calculate the amount of blood transfusion according to sex and weight . Women weigh no more than 50kg The amount of blood transfusion is 200 ml , otherwise 250 ml ; Men weigh no more than 60kg The amount of blood transfusion is 250 ml , otherwise 300 ml .

9. When the temperature is higher than 26℃ when , Need to turn on the refrigeration air conditioner ; The temperature is lower than 10℃ Turn on the heating air conditioner ; In other cases, you only need to turn on the air supply mode . Compile automatic temperature control program , The control operation outputs the corresponding prompt string to simulate , such as “ Turn on refrigeration ”

10. according to 《 Sales Tariff of provincial power grid 》, Household electricity consumption is subject to 3 Gradient charge : Monthly electricity consumption 150 KWh and below , Per kWh 0.4463 element ,151—400 The kilowatt hour part is 0.4663 element ,401 The part above kilowatt hour is 0.5663 element ,  Please write the program , When inputting the user's electricity consumption , Work out the expenses to be paid .

11. Assuming that the A Ground to B The local train tickets have hard seats and hard sleepers , The prices are 100 and 190 element .  According to the regulations of the railway department , minors (18 Under one year old ) Not tall enough 120cm Free of charge ,120( contain )-150( Not included )cm Half fare required ,150 And above require a full ticket , The minor berth can only be reduced by half the price of hard seats . Please design a ticket purchasing procedure , Age and height are required ( Minors need to enter ) And the type of ticket , The price of the output ticket .

12. Output the maximum number between two numbers

1. The user enters a number , Determine whether the number is odd or even , If it is not a number, you should also give a prompt

        var num = prompt(" Please enter an integer ")*1;

        if (num % 2 == 0) {

            document.write(num+" even numbers ");

        } else {

            document.write(num+" Odd number ");

        }

2. Determine the maximum value between two numbers ( The user enters two numbers , Determine which number is larger )

        var str1 = prompt(" Please enter a number 1")*1;

        var str2 = prompt(" Please enter a number 2")*1;

        if (str1 > str2) {

            document.write(" The maximum number is " + str1);

        } else {

            document.write(" The maximum number is " + str2);

        }

  3. Judgment of grade

        var grade = prompt(" Please enter your score ") * 1;

        if (grade >= 90) {

            document.write(" good ");

        } else if (grade >= 80) {

            document.write(" good ");

        } else if (grade >= 70) {

            document.write(" commonly ");

        } else if (grade >= 60) {

            document.write(" pass ");

        } else {

            document.write(" fail, ");

        }

 4. The user enters a year , Determine the number of days in the year

        var year = prompt(" Please enter the year ") * 1;

        if ((year%4==0&&year%100!=0) || year%400==0){

            document.write(year+" Years have 366 God ");

        }else{

            document.write(year+" Years have 365 God ");

        }

   5. Make a study schedule , Enter the day of the week , Can you remind me what courses to learn today

        var day = prompt(" Please enter the day of today :");

        if (day > 0 && day <= 7) {

            switch (day) {

                case "1":

                    document.write(" Today Monday , Learn Chinese ");

                    break;

                case "2":

                    document.write(" Today is Tuesday , Learn math ");

                    break;

                case "3":

                    document.write(" Today is Wednesday , Learn English ");

                    break;

                case "4":

                    document.write(" Today is Thursday , Study physics ");

                    break;

                case "5":

                    document.write(" Today is Friday , Learn chemistry ");

                    break;

                case "6":

                    document.write(" Today is Saturday , Sleep in ");

                    break;

                default:

                    document.write(" Today Sunday , Have a rest ");

                    break;

            }

        } else {

            alert(" There's only... A week 7 God !!!");

        }

6. The taxi , Start at (2 km ) by 7 element , exceed 2 Kilometers per kilometer 3 Yuan calculation . It is required to calculate the cost according to the distance

        var km = prompt(" Please enter the number of kilometers :");

        // var sum;

        if (km > 0 && km <= 2) {

            document.write(" The cost of this trip is 7 element ");

        } else if(km>2){

            sum = 7 + (km - 2) * 3;

            document.write(" The cost of this trip is " + sum + " element ");

        }else{

            document.write(" It's impossible to spend money !!!");

        }

7. Judgement of leap year ( The condition of leap year is that it can be 4 to be divisible by , But can't be 100 to be divisible by ; Or can be 400 to be divisible by .)

        var year = prompt(' Please enter the year ') * 1;

        if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {

            document.write(year + " Year is a leap year ");

        } else {

            document.write(year + " It's not a leap year ");

        }

8. Calculate the amount of blood transfusion according to sex and weight . Women weigh no more than 50kg The amount of blood transfusion is 200 ml , otherwise 250 ml ; Men weigh no more than 60kg The amount of blood transfusion is 250 ml , otherwise 300 ml .

            var a = prompt(" Please enter your gender ");

            var b = prompt(" Please enter your weight ");

            if (a == " Woman ") {

                if (b <= 50) {

                    document.write(" Your blood transfusion volume is 200 ml ");

                } else {

                    document.write(" Your blood transfusion volume is 250 ml ");

                }

            } else if (a == " male ") {

                if (b <= 60) {

                    document.write(" Your blood transfusion volume is 250 ml ");

                } else {

                    document.write(" Your blood transfusion volume is 300 ml ");

                }

            } else {

                document.write(" Please enter the correct gender ");

            }

9. When the temperature is higher than 26℃ when , Need to turn on the refrigeration air conditioner ; The temperature is lower than 10℃ Turn on the heating air conditioner ; In other cases, you only need to turn on the air supply mode . Compile automatic temperature control program , The control operation outputs the corresponding prompt string to simulate , such as “ Turn on refrigeration ”

        var temperature = prompt(" Please enter the current temperature :(℃)");

        if (temperature > 26) {

            document.write(" Turn on refrigeration !");

        } else if (temperature < 10) {

            document.write(" Turn on heating !");

        } else {

            document.write(" Open air supply !");

        }

10. according to 《 Sales Tariff of provincial power grid 》, Household electricity consumption is subject to 3 Gradient charge : Monthly electricity consumption 150 KWh and below , Per kWh 0.4463 element ,151—400 The kilowatt hour part is 0.4663 element ,401 The part above kilowatt hour is 0.5663 element ,  Please write the program , When inputting the user's electricity consumption , Work out the expenses to be paid .

        var a = prompt(" Please input the monthly electricity consumption ( kw ):");

        var price;

        if (a > 0 && a <= 150) {

            price = a * 0.4463;

            document.write(" The electricity charge you need to pay is " + price + " element .");

        } else if (a > 150 && a <= 400) {

            price = (a - 150) * 0.4663 + 150 * 0.4463;

            document.write(" The electricity charge you need to pay is " + price + " element .");

        } else {

            price = (a - 400) * 0.5663 + 250 * 0.4663 + 150 * 0.4463;

            document.write(" The electricity charge you need to pay is " + price + " element .");

        }

11. Assuming that the A Ground to B The local train tickets have hard seats and hard sleepers , The prices are 100 and 190 element .  According to the regulations of the railway department , minors (18 Under one year old ) Not tall enough 120cm Free of charge ,120( contain )-150( Not included )cm Half fare required ,150 And above require a full ticket , The minor berth can only be reduced by half the price of hard seats . Please design a ticket purchasing procedure , Age and height are required ( Minors need to enter ) And the type of ticket , The price of the output ticket .

			var age = prompt(' Please enter age ')*1;
			var tick = prompt(' Please enter the ticket type ');
			if(age>=18){
				if(tick==' Hard seat '){
					document.write("100");
				}else{
					document.write("190");
				}
			}else{
				var height = prompt(' Please enter height ')*1;
				if(height<120){
					document.write(" free ");
				}else if(height<150){
					if(tick==' Hard seat '){
						document.write("50")
					}else{
						document.write("140");// Here is the height of minors 120-150 Bought a hard sleeper ticket  190-50( Half price of hard seats )
					}
				}else{
					if(tick==' Hard seat '){
						document.write("100")
					}else{
						document.write("190");
					}
				}
			}

12. Output the maximum number between two numbers

        var str1 = prompt(" Please enter a number 1");

        var str2 = prompt(" Please enter a number 2");

        if (str1 > str2) {

            document.write(" The maximum number is " + str1);

        } else {

            document.write(" The maximum number is " + str2);

        }

原网站

版权声明
本文为[Luqi zz]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207070322309506.html