Group Group Group Group Group Group Group Group Group

raywenderlich.com Forums

Kotlin Cheat Sheet and Quick Reference

Download a handy 2-page PDF Kotlin Cheat Sheet and Quick Reference!


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/6649-kotlin-cheat-sheet-and-quick-reference
println(15.fizzBuzz()) // Prints fizz when it should print fizzbuzz

Code should be:

fun Int.fizzBuzz(): String {
     return when {
         this % 15 == 0 -> "fizzbuzz"
         this % 3 == 0 -> "fizz"
         this % 5 == 0 -> "buzz"
         else -> this.toString()
     }
}

@accordionguy Do you have any feedback about this? Thank you - much appreciated! :]

You are correct! I don’t know how that one slipped by (I ran all the examples in a “harness” project in Android Studio), but apparently it did. Thanks for catching it; I’m going to see about getting a correction made to the cheat sheet.

— Joey