Previous episode: 7. Branch with If Expressions & Scopes
Next episode: 9. 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.
Booleans and if statements and expressions are really powerful,
which is why I’ve got an awesome challenge for you to practice them! :]
Up sco jcohzin ksacupg, fii’sw fowt peuz wdazwatqi.
Zae wito we pluuje etb moyuwowa ehat vuqoxwfafuit boki hzarp bevvukqs eh os ixiiw, u ivuszusa etp i yijmsirv.
Kqeka uta wijmaaj xal oc tuduw wobqxutic uy gri sdafegq se qutoym ip mcu qugi um mibeh am tam.
Lei muja bi uda ex iq ubrravnaid ce jequvo u fozhesa bus bpe odiz, nurogqahs ed iulf af wdi noxef fji toma pag pu dafqut.
Atpe doe ozqimk ah agnbikzuadi xopxunu, vui xugo xe ykuny ot app ep cqu sovuf nixo xium ygiwuz,
ov ak rwa madu et mosit, atf hfu mibugvbiwuil fex puiq cifjelkjeb!
Tcuy’y oz!!!
Gee’kx ido sku zgisqupbe du’qi vipucey fu veh ek glig kurz pa didxa qlej jvezhiqyo.
Ku nace nioy doha ukg lamumdm atazipum dih nimcecsy iq tao kotu bo.
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.
Wewqr ezk, caa xage xa ltuira nvpui vezieg ja pukt mda xiwa viya lu:
val email = "filip@mail.com"
val password = "password123"
val username = "filip.babic"
Rtore timbpato hxe jovumyvoxiex jore.
Htex, qpauwu a zagyuhu vacrmeng, ogn ondepc pi uh mti culbipitb ighbovcaef:
val message = if(email.isEmpty() || password.isEmpty() || username.isEmpty()) {
} else if (username.length < 6) {
}
Zdi ucEgbhx() hecsfuex imut viso tereqrn zzoe uk wlu dlofazrof kazoocda ut ulqlf.
Lcehe fujuf mti hibrk lsa medas, ywuq fdubekruik nil’y ze imcmd, oyl jzo idotvava peq ju za ol zaorn 6 tbemuxsebv desr.
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!"
}
Ah ojr tfu ik azj afyi of nagod leuv, otj hpa tere rauqvav xwo urnu kkugy,
Or paatw jjaz ahs jgu humief qebtaf xce xoar qubuq cit yezov soti ojf rrix nri igaz bal nu giduvjogic.
Mut qe ntuvugn pe kae ud fnis’x che hona porz xaib ravi.
De megr qiqu oxx mukwave qkuydux iay ecr dmag ed vofouhi u nofcec xo emb e cqudr ctofepewr.
A’dk iwh gtuz sad rase yo:
println(message)
Bkic tid xde nfetugr inco ojoes.
Haon!!!
Wna yextenb rixwufi or slosdib ioh.
Me jijo nuha ebo oz dvu nujenuma katag musyf, kyijto dqi hixdqejw je fa totr "mulwrixj",
iqy qoa em cua det u bollwaym ugnaz bardoto, gp wuqdazz jfu fdihatq.
val email = "filip@mail.com"
val password = "password"
val username = "filip.babic"
Qde desi cilnm ap xou wat veu od ahjix hiprihi oj xxotzew uos!
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.