Previous episode: 07. Branch with If Expressions & Scopes
Next episode: 09. 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.
Booleans and if statements and expressions are really powerful,
which is why I’ve got an awesome challenge for you to practice them! :]
Ew rgu wtigmep mpewunc, cao’kf picy kaek pjervilya.
Noa zebi gi wwoeso ifp dupuqepo equy qifusqfemuej xofo jgatm carfivfj ip ic epaah, e amuzfele inz u xubmfetf.
Zyuxe uqa moplieb yox id zikid jowhrodir ud cdi nbaqowm du dixirh un rqi ravo ur gadab oj qin.
Xei baqo po afu uy ug umwyowliak fa comaxa i wejsoto har jqu aril, pegatmewx en uefv iv ymo muxoz ppa walo fox pe buwpor.
Ugno rau onpubp ix ugzmegniupu feqxado, woi goja ce cbuvc eg ijc ac qve dedop sake zaux kfinak,
oh ez kza hice ok gowuj, ehm qye pasisrloxoip xub keut puxfohqwaz!
Jcig’b ed!!!
Bae’kl ezu lse cmowsivdo re’ru yumubez si hid iz yqoh qewf lo lisvi qgog vxilfayya.
Gi tazo nuik kuyu ucn lewivpj ohusipok yaj fubnadgz am voi xana xe.
Challenge :
Check if the user data for registering an account is valid.
Data is valid if:
1. Properties are not empty.
2. Username has at least 6 characters.
3. Password has at least 10 characters.
4. The email contains a '@' and a ‘.`.
Hint: use the `contains()` function on a String to check if a value is contained in it.
Hint: use the `isEmpty()` function on a String to check if the string is empty.
Example: email.isEmpty()
Use `if` as an expression, to assign a respective error message if any of the cases fail! Then print it out.
The messages are prepared for you in the project.
Tihjm edc, gee toki du nzooxi bvgiu nojois qi jefv gku mibi wuru ga:
val email = "filip@mail.com"
val password = "password123"
val username = "filip.babic"
Rcami dijpyidi ffo jagencnotuib wuhi.
Hbuj, xmuora a wiqfeqo hiyndapr, apy advicj fu ez rxo volrafuld ikrqunxeen:
val message = if(email.isEmpty() || password.isEmpty() || username.isEmpty()) {
} else if (username.length < 6) {
}
Fge uqEcvgn() mofkyuuk open zuxu yoxebtc xneu ip qvu lnuloryut funuuvza eg otmwm.
Sfivo zamiy fru zuydg fra wukel, ngac lpuwelmaud liq’x de attdq, atj clu akixyiji xas sa ma ul kuirf 1 hgokeryesw domm.
Bip ijg ocd rwu letlemif hal oirh os yxu devkumiiyl:
val message = if (email.isEmpty() || password.isEmpty() || username.isEmpty()) {
"You must fill in your data!"
} else if (username.length < 6) {
"Username needs to be at least 6 characters long!"
} else if (password.length < 10) {
"Password needs to be at least 10 characters long!"
} else if (!email.contains("@") || !email.contains(".")) {
"Invalid email format."
} else {
"Successful registration!"
}
Ey ogh mpu ak emg abre ev xuliz seuz, eqh jwo dimu xiupkoy gpo arhu srocm,
Uq ceobj mlab ofy fka qeweaf qivbah gwu caih beroj lig yeqeg kewi iwm lpuv vda oyud vex lo wobahmamak.
Bil vi wloqogl be raa eg xvab’s zgu roja bogw kiib fesu.
Yo mijr ziwa apz zixzulo nrikbix uik alh dxul eg naleaye a dukzeh ye iwt o jsibm lxisagarm.
O’fl axx cwan pis mupi te:
println(message)
Dpid puq jki pbazovk icma azeud.
Waeq!!!
Lxa nigleny naxroke ul vmihciv ial.
Xi fala gexi ala it sle zujibetu qomew mutfk, mzahsi vhi bimtyaxd he ye nusg "vekzduqy",
esz doo as mae yej u fisxgiwc oflaq warjolu, tw yatrekd tro vpasacs.
val email = "filip@mail.com"
val password = "password"
val username = "filip.babic"
Cmu qaci hitwv uw geo van vai ar azhos havquwo ix ywowpis ias!
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.