| Snippet Name: | Ternary Operator |
| Submitted By: | Mark |
| Description: | This is a very quick way of creating conditional statements. Especially useful when you need to make a lot of conditional statements that make up much of your code. |
Snippet
- // long version
- if (age>17) {
- category = "Adult";
- } else {
- category = "Underage";
- }
- category = age>17 ? "Adult" : "Underage";
- // another use
- amountOfGuests = 1;
- pluralOrNot = amountOfGuests>1 ? "s" : "";
- trace("You have "+amountOfGuests+" guest"+pluralOrNot);
