//else if with ternary if
var x = Number(prompt('Enter number'));
(x < 10) ?
alert("Your number C")
: (x >= 10 && x <= 15) ?
alert("Your number B")
: (x >= 16 && x <= 20) ?
alert("Your number A")
: alert("Other");
condition ? exprIfTrue : exprIfFalse
The conditional (ternary) operator is the only JavaScript operator that takes three operands: a condition followed by a question mark ( ? ), then an expression to execute if the condition is truthy followed by a colon ( : ), and finally the expression to execute if the condition is falsy
MALE = True
FEMALE = False
# (if_test_is_false, if_test_is_true)[test]
gender = ("female", "male")[MALE]
print("You are a ", "male")
# Output: You are a male
# (if_test_is_false, if_test_is_true)[test]
gender = ("female", "male")[FEMALE]
print("You are a ", "female")
# Output: You are a female
condition = True
# (if_test_is_false, if_test_is_true)[test]
print(2 if condition else 1/0)
#Output is 2
condition = False
# (if_test_is_false, if_test_is_true)[test]
print(2 if condition else 5)
#Output is 5