0

Can we have more than two values for the conditional(ternary) operator

14th Jun 2016, 11:08 AM
Ozii
Ozii - avatar
4 Answers
+ 1
No, remember that the sintax is as follow: condition ? expr1 : expr2 The condition is an expresion that evaluates to true or false. If the condition is true the operator returns the value of expr1, otherwise it will returns the value of expr2. A condition can have multiples "conditions", for example: // you can use prompt var num = 12; (num > 0 && num % 2 == 0) ? alert("Is positive and an even number") : alert("Is negative or odd number"); This case will show Is positive and an even number
14th Jun 2016, 6:24 PM
Gabriel Alejandro Lopez Garrido
Gabriel Alejandro Lopez Garrido - avatar
0
is the cuestion about the condition or about the result of the condition??? If it is about the result the answer of Gabriel Lopez Garrido is flawless. If is it about the condition, you can have as many as you want: if((condition1) && (condition2) || (condition3))...
24th Jun 2016, 11:07 AM
Gabriel Marazzi
Gabriel Marazzi - avatar
0
Level.setTime(0); ClientMessage("ITS DAY IN MINECRAFT NOW");
13th Aug 2016, 6:43 PM
TheBestCoderIntheworld
0
clientMessage("HI GUYS"); Level.setGameMode(0);
13th Aug 2016, 6:44 PM
TheBestCoderIntheworld