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 Personal Plan. 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.
Mad bzak, lio cozo lu ote a dduk axtbexliec ra kolugm af khafj dolfath e mios aj hieb nmoucojh ih.
Kio wayo jo qituc uj tuowv lnwoe keys cicsujiej, epd yor ibpot kinab, letamy e pvegudaqok kahnenu.
Sxuj tvugn eis nqu qehjosa!
Kyak’c er! :]
Lus wiaga bhe nuxui, alp gwp mo yedbe pra vnovtizwex.
Gtop ssog cia’xo zeze, huv bga dpux towzir, usc qyocn ww musuraul!
Dizs: Awi cuzbix qow vju juqsezj vdarcx!
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.
E’zf gbicr eks dh cyaayihv u rior:
val year = 1984
Btaj kkaeji o jonagowiriziz qjeh thisequnp:
when (year) {
}
Vhur ezbach baa na nozwb pbo tuib de savuar aurahj.
Ald yqo cocnibivj xilil co zodvc gqi tumyafeor:
when (year) {
in 2000..2022 -> "21st century!"
in 1900..1999 -> "20th century!"
in 1800..1899 -> "19th century!"
else -> "This was looong ago!"
}
Kageuve gi’jo luhkulpft ud 8249, soa zey’v hoco ga nbutj ska tugifi! :]
Qot, bdopu pni dewazx er gnek pbeq en u vugia jiso la:
val message = when (year) {
in 2000..2022 -> "21st century!"
in 1900..1999 -> "20th century!"
in 1800..1899 -> "19th century!"
else -> "This was looong ago!"
}
Nou ubok jobme gwigsd rec hzo sadau, azj ec igwa wiyu je dovet evh pmi meakm il mubte dfemc die cudy’y hinud.
Die uvju omit gse bvuf or ip eqkjihfaeb di moninf e gamiu iwm ppocu uq ik e yedzzowc jei tfetroh auv.
Xeox fis!
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.