If-Else Expression in Kotlin

Level 277 keystrokes

Uses if-else as an expression whose result is assigned to a variable.

Kotlin code

// Store the score 85
1val score = 85
// In Kotlin, if-else is an expression that returns a value
// 85 >= 60 is true, so grade becomes "Pass"
2val grade = if (score >= 60) "Pass" else "Fail"
// Prints Pass
3println(grade)

Output

Pass
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 Kotlin code and how often they appear.

  • "× 4
  • =× 3
  • (× 2
  • )× 2
  • >× 1

More Kotlin examples at level 2

← Kotlin typing practice