Trinocular operator
What is : Perform different actions/return different values according to different conditions
syntax : Condition 1, value 1 or Action 1://If Condition 1 is met, return value 1 or perform action 1
Condition 2 = value 2 or action 2://Otherwise, if condition 2 is met, return value 2 or perform action 2
...? ....: default value or operation; Otherwise, (none of the preceding conditions are met)//perform the default action, or return a summary of the default values: Multiple conditions, multiple events, multi-select one execution.
JS: If the operation of the statement is relatively simple, it is recommended to use three mesh operation instead of IF. Else
Summary: an expression? " Leap year ":" Common Year "
A variety of conditions 1? Value 1: Condition 2? Value: Value 3
The test questions are as follows:
2. If total>=500, call 80 percent, (less than 500 do nothing)
var money=prompt ("Please enter the amount of the item you have purchased ()");
var total=money*0.8;
money=money>=500?total:money;
document.write (Money);
/*3. Despise the question * *
If the user enters a reply, the user input is displayed
Otherwise, "The owner is lazy and nothing is left."
var reply=prompt ("Please make your comments");
Reply=reply!= ""? Reply: "The host is very lazy, nothing left";
document.write (reply);
Judging True/false
var name1= "Scott";
var name2= "John";
Name=name1>name2? " True ":" false ";
alert (name);
Test questions
Ask the user to enter a year to determine if the year is run:
Condition: The year can be divisible by 4 and cannot be divisible by 100 or the year can be divisible by 400
var year=prompt ("Please enter a year");
Year=year%4==0&&year%100!=0? " Leap year ": Year%400==0?" Leap year ":" Common Year ";
document.write (year);
/* Calculate the Leto index:
klt= Weight/(height * height)
Klt>25 Fat
<20 Skinny
Normal
*/
var stature=prompt ("Your height (m)");
var weight=prompt ("Your Weight (kg)");
var klt=weight/(stature*stature);
Klt=klt>25? " Fat ": klt<20?" Thin ":" normal ";
document.write (KLT);
Use of the JavaScript three mesh operator