- 01Setting up (what you'll need)
- 02Your first output (print)
- 03Variables and types (var and annotations)
- 04Null safety (? and !)
- 05Branching (the if statement)
- 06Repeating (the for loop)
- 07Writing your own function
- 08Repeating (the while loop)
- 09Working with lists (List)
- 10Working with maps (Map)
- 11Classes (object orientation)
- 12Constructors
- 13Inheritance
- 14Named arguments
- 15Asynchronous work (Future, async, await)
- 16Working with strings
- 17The switch statement
- 18The ternary operator
- 19Extension methods
- 20[Project] Build a small inventory system
The ternary operator
This lesson covers the ternary operator, which fits an if statement onto one line.
Writing condition ? value_if_true : value_if_false picks between two values on a single line.
The sample code uses the ternary operator to decide between "Pass" and "Fail" based on int score = 75;.
A common early stumble is overusing it until the code becomes hard to read. It is handy for a simple branch, but nesting them tends to make things less clear rather than more.
In professional work, the ternary operator turns up constantly inside Flutter UI code for switching a displayed value on a condition.
๐งช This site can't compile or run Dart directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ nothing is sent anywhere).
