Exercise-01 Judging odd even numbers
var num =prompt ("Please enter a number");
Alert (Num%2==1?alert ("odd"): Alert ("even"));
Exercise-02 Judging the number of daffodils
var num = prompt ("Please enter a three-bit positive integer:");
var a = parseint (num/100);
var B = parseint (NUM/10)%;
var c = num%10;
var sum = a*a*a + b*b*b + c*c*c;
var result = sum = = num? "The number of daffodils": "Not the number of daffodils";
Alert ("you entered" +result);
Practice-03 Membership card four-digit sum, membership card four-digit sum greater than 20 o'clock will rebate 50 yuan, otherwise no rebate:
var num=prompt ("Please enter your membership card number")
var a = parseint (num/1000);
var B = parseint (num/100)%10;
var c = parseint (NUM/10)%10;
var d = num%10;
var sum = a+b+c+d;
var result=sum>20? " 50 ":" 0 ";
Alert ("Your rebate is" +result+ ");
Exercise-04 Payroll income tax pay more than 1000 of the portion required to pay personal income tax, the output after-tax wages:
var num =prompt ("Please enter your salary");
num<1000? Alert ("Your after-tax salary is" +num): Alert ("Your after-tax salary is" + (num-(num-1000) *0.05));
Practice-05 users to buy goods, three items have a more than 50 yuan, or the total price of more than 100 yuan, that can play 85 percent, otherwise no discount:
Method One:
var a =parsefloat (Prompt ("Please enter the price of the first item)");
var b =parsefloat (Prompt ("Please enter the price of the second item"));
var c =parsefloat (Prompt ("Please enter the price of the third item"));
var sum =a+b+c;
(a>50| | b>50| | C>50) | | Sum>100?alert ("Your final Price is" +sum*0.85+ "): Alert (" Your final Price is "+sum*1+");
Method Two:
var a =parsefloat (Prompt ("Please enter the price of the first item)");
var b =parsefloat (Prompt ("Please enter the price of the second item"));
var c =parsefloat (Prompt ("Please enter the price of the third item"));
var sum =a+b+c;
If(a>50| | b>50| | C>50) | | Sum>100) {
Alert ("Your final Price is" +sum*0.85+ ")
}
else{
Alert ("Your final Price is" +sum*1+ ")
}
Exercise-06 Determine if the year entered is a leap years
var num =parseint (Prompt ("Please enter the year you want to query");
Num%4==0&&num%100==0||Num%400==0?alert ("You are querying for a leap year"): Alert ("The year you queried is common year");
Exercise-07 Edit Arithmetic calculator: Two numbers of subtraction arithmetic
Method One:
var num1 = parsefloat (Prompt ("Please enter first number:"));
var fu = prompt ("Please enter the operation symbol:");
var num2 = parsefloat (Prompt ("Please enter second number:"));
var result = 0;
result = fu== "+"? Num1+num2:result;
result = fu== "-"? Num1-num2:result;
result = fu== "*"? Num1*num2:result;
result = fu== "/"? Num1/num2:result;
Method Two:
result = fu== "+"? Num1+num2: (
fu== "-"? Num1-num2: (
fu== "*"? Num1*num2: (
fu== "/"? Num1/num2: "Incorrect input"
)
)
);
Alert ("The result is:" +result);
Exercise-08 to find the maximum value of three variables
Method One:
var a =parsefloat (Prompt ("Please enter the first variable"));
var b =parsefloat (Prompt ("Enter a second variable"));
var c =parsefloat (Prompt ("Please enter a third variable"));
if (a>b| | C>B) {
if (a>c) {
Alert ("Maximum value is" +a)
}
else{
Alert ("Maximum value is" +c)
}
}
else{
Alert ("Maximum value is" +b)
}
Method Two:
var a = prompt ("Please enter the first number");
var B = Prompt ("Please enter a second number");
var c = prompt ("Please enter a third number");
if (a>b) {
if (a>c) {
alert (a);
}else{
alert (c);
}
}else{
if (b>c) {
alert (b);
}else{
alert (c);
}
}
Method Three:
var a = prompt ("Please enter the first number");
var B = Prompt ("Please enter a second number");
var c = prompt ("Please enter a third number");
if (a>b) {
alert (a);
}else if (b>c) {
alert (b);
}else{
alert (c);
}
Some simple exercises and applications of JS operators