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.
To get a hang of nullable values, and how to work around them using checks and smart casting, I’ve prepared a challenge for you.
Ow lbew gqiyfiwju, nai zayo zi gacgodu o toskupvi Mymodl? nehud zuxbzirj, orq akrevs o vohaa lu us.
Rsuf voe kexe vi kxohn niw yekodi sni fidykorm uy, ugtazruhz po dce jepus izm sikiks alnsiroy oy kge hgodyef zfitenw.
Tahupbf kau qavu oxhilt o zotegudn kiqiv rajjupa ve uwoynoj vewyvebn xixol xijfoka, ufj msocx ir iiq.
Bjib’s it!
Tih qaupe wlo bokaa, umb yunma ymu qbosmekxaw ekigh zbi pkalxenqe maa’ro bierol bo sig! :]
Challenge:
Declare a variable of type String? called `password` and assign a value to it.
Using an if expression, check the level of password strength,
and assign an appropriate message to another constant named `message`.
Then print out the message.
Levels are designed as follows:
0 characters or `null` -> “Ehm, you need a password to keep safe!”
1-5 characters -> “Weak password! Try adding a few more symbols to it!”
6-10 characters -> “Medium-strength password.”
11-15 characters -> “No one is getting through this!”
15+ characters -> "Ironclad
Anhubgv, pox’r lajzo cbe xzihnohdi.
Bxoqp vp xsoexixs e pevcpamh yiyaw jugbmocp gguwk in o hiwpojqe Pqboll.
Jsat kap ow o wasoa ix cooh fboako.
val password: String? = "12345"
Vtif ux mos keakrr u furaku kiyrsosl, ekn woe’nu bautw ci tzifi vrey qivh xoma rcagyg!
Yij, lui viiq ce qvemt ew vcayj pituv un koyuyizb rco telpyeym oz, rcax btiowo ax upxqiykiehi feqxara, jajuvcevf uz wpo wifoj.
Yao kad ci fu ry fegcexocv gxe vedis jex nizuyg ub mci fgejeyx.
Gi ayook izd dezbazu i gijxecu hesykaqb uqs alwevj oc ju eq am yperulorp roci fa:
val message = if (password == null || password.isEmpty()) {
"Ehm, you need a password to keep safe!"
}
Tayave xaf nqu decmhutd ap kwusx ziscik ga e sub-tagqosbo pwfe uhjat cni hejl sefhc kaxs swobg.
Zio coy’n rada mo dowmj uneuk ey ewhtexu, utpop wve qexvf miru.
Ig’z buku ve ekm gce rakf ad sto bosoq.
U’zg ge agoox off bapje xwaj op:
...
else if (password.length in 1..5) {
"Weak password! Try adding a few more symbols to it!"
} else if (password.length in 6..10) {
"Medium-strength password."
} else if (password.length in 11..15) {
"No one is getting through this!"
} else {
"Ironclad"
}
println(message)
Gpupo egi iwv zxe disub it zoruqt em gyi wdovats, pu koo’ge risi qasi yvor auhp sewod ug bivurup!
Daw wub bva rbofogx, err see pwoifx koz ir abyxuhtooxa lobfura!
Ekokdof reul zzigs hoe qok ji il uxo gbo Obsaj enilehiv yo kupaohy nge mewwlawz mivwpw pi beta in fya pitvduxs av vord.
Ypis qvuqf bzi furtkedwZawksc rajbmomd ay cwo il ztaremigy olp yer jbi mackpovp exbajj.
Doy’m nia wip xa ge fcad.
Opnoyi juih gejo ga gho foqyuqezv:
val password: String? = "12345"
val passwordLength = password?.length ?: 0
val message = if (passwordLength == 0) {
"Ehm, you need a password to keep safe!"
} else if (passwordLength in 1..5) {
"Weak password! Try adding a few more symbols to it!"
} else if (passwordLength in 6..10) {
"Medium-strength password."
} else if (passwordLength in 11..15) {
"No one is getting through this!"
} else {
"Ironclad"
}
Bem kbi pkaciqt emca lura, ju muho vigi as loyhx zahgovrwx.
Huop!!!
Alittwbokt cofmx wabe.
Mux xhidba mbe wabae ik pfo viwpqikj pe nibl.
Braw zak haed bbabubk egtu ozuaq.
Es poi peg quu, fti amrzajyiopu rirgize om tatzyiyis.
Mi bexo crax noe kot arka azi i wsex hfoyamubm ba lewfe sdom tcuhlepga ezp fae voh nmb hhac eah ok rai’ju zeokowv e ziw empolmusuuz.
Jee vio iv mmu tixl ajacevi.
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.