Ternary Operator in Swift

Level 127 keystrokes

Uses the ternary operator condition ? a : b to choose a string; since 5 > 3 is true, it prints "Yes".

Swift code

// Gives "Yes" if 5 > 3 is true, otherwise "No": Yes
1print(5 > 3 ? "Yes" : "No")

Output

Yes
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Swift code and how often they appear.

  • "× 4
  • :× 1
  • ?× 1
  • (× 1
  • )× 1
  • >× 1

More Swift examples at level 1

← Swift typing practice