View Full Version : Who has ever seen a condition written this way?
01-18-2012, 04:59 PM
The "?" seems to be called the conditional operator.
var points = prompt('How many points do you want on ten?');
var result = (points >= 5) ? "succeeded!" : "didn't succeed ;-)";
window.alert("You " + result);
01-18-2012, 05:05 PM
This is called a ternary operator. As the name indicates ternary operators take three operands. The syntax is condition ? result1 : result2;
It is often used as a shortcut for an if..else statement.
For more info Google, e.g.
All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
01-19-2012, 03:06 PM
All right, that'll do it.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.