What does the "?" and ":" do in this Code

econjack:
If you wrote a simple if statement like:

if (val == 10) {

x = 20;
} else {
   x = 15;
}



You could write the same code using the ternary operator as:



x = (val == 10) ? 20 : 15;




If the conditional expression (val == 10) is True, the expression following the question mark is evaluated. If the conditional expression is False, the expression following the colon is evaluated.

This is where I'd have gone ...

"No, Mr Engineer Sir.... NO NO NO NO NO NOOOOOO"

 if (x ==10) {?=20 else 15};

would make more sense...