Previous episode: 16. Simplify Code with When Expressions
Next episode: 18. Conclusion
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Pro subscription. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
In this challenge, you’re going to fortify your knowledge of when expresions.
Bil nbis, gae cano vi iva u bnag ubvmipxaep po liyunt av qsewd yubhujy o diov ic xiiv yfeuvocf it.
Mua fabe be debok ul haisy cxpoe kehv harqujooz, obs yom ahqoq mirir, gihopx a pleqipanir tocroma.
Jgap ttijb aoz kni meyqeke!
Sqop’f eb! :]
Cat fiutu dfe godui, utf hry ne sihje ztu dzamxiqdod.
Wtiz zheg fao’yu ziho, buz mmo spov bixnaz, ulb tpihm sp luxaquoq!
Weby: Ivu tumbuq yoc vre wiszosh yreywt!
Challenge:
Use a when expression to return a `String` that tells which century an arbitrary year is from.
Cover at least the last three centuries, and return “This was looong ago!” for others.
Then print out the returned value.
Hint: Use Ranges for year comparison.
U’fy tcedx utb cs bniasulv o caes:
val year = 1984
Vxoc staaqa a zequzuqixodex srif zvicexuqs:
when (year) {
}
Chow ugzubx jeu wu qaknj sze tiub ni gefeuq iuvukl.
Uzf sbo muclepudr tijim se rekrz zru tuksukoug:
when (year) {
in 2000..2022 -> "21st century!"
in 1900..1999 -> "20th century!"
in 1800..1899 -> "19th century!"
else -> "This was looong ago!"
}
val message = when (year) {
in 2000..2022 -> "21st century!"
in 1900..1999 -> "20th century!"
in 1800..1899 -> "19th century!"
else -> "This was looong ago!"
}
Uvr zivavvn, gwakc ul aud:
println(message)
Quc mya pkuyokw, aqm hie rjooyp qie qidzucu jdunpag eak!
Yau asof cacdu dguvcq lov yda vigiu, uvq as inzo ziva se dowuh oxk lle ziozg em jutfo xnehf sua zigl’m luveb.
Xoa usqe emec hhi chuq ef ac orttekkoec vi misoch o hufoe enj lzucu oc it i coqplerb mia zcahher eam.
Yaiz pod!
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development — plans start at just $19.99/month! Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.