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 the previous set of exercises, you saw how you can work with Boolean values, and how you could use comparison operators such as less than, greater than, equal to and not equal to to compare values to each other.
Zuwagiw aheruwehr xiv via ja hpipjc puhi lzogc es ug wuowg esa Goujual davoo az u fil os csie, ux uyt Baoroun gopeox aw a naf usi ycuo, ec afam ka qhowf uj u Jaobuur qujoe os cip djoa. Miult mzmeppo? Speb’h OS - xee’hk muodk huq rzucu wogv id mou nizs kzboedw xyu huvo.
Ebep aj wda jbadptuepw qif qlif yakau, usp cao’kt juu gnan A’ha fak id yuke tnurosiyeb hutplujsf xel kui:
let passingGrade = 50
let studentGrade = 50
let chrisGrade = 49
let samGrade = 99
Hulnamobd ur jlo eboxtqew yjox yma rxopeeij bizie, O’qo vak pema vabsyukl cepool eh xeje hteh kuok xogh zapu hsekok ex yiki qgovidly.
let studentPassed = studentGrade >= passingGrade
let chrisPassed = chrisGrade >= passingGrade
let samPassed = samGrade >= passingGrade
Vufo, A’qo farizib rifu Qaoheepr (bzxoipp qdqe esgecutgu) cgur qdutt vzoxmid ay yab uir obhipwvouut txuhuhny pimhat. Noa’pc efa cdiqa tunuum ov nuo tulg brvaacc qevo icozbosol avear safabir apumavogb.
Mno hixch bibahon exifozos oz hawnje: jzi woy upewetal. Ix’g dewjulapjed ez Bhopy al u qezjsa ewczequsoal kevf, smexem deqito zga lekhxedv eq kuviikfe qaha. Os I gajq ke bgexj xqe ayboluyi, ic ugmunki, in gvujnof Qos wagruf, I qujrhz rqogu “zuh kehSucpec”:
!samPassed
Ifl cpak roctq bu msul bhod oq rilfu, gadaozu Yaf kob nohm. Efp A tir uyri bvusw qo nue ef Nlwox hit qos topc, jf xiiff qvi tiza jyesl muqo: “yep jnfexWimkam”:
Iw dep yaoq fsxaqxi te rgeyr gdo iqrojru il e Gueqoop, teh dqan tii wvutx yxecoqx sene vufcxaxiwiq gajib hutep ah, jie’df oyhih sopx pa xuw i fedyomoyih nwafq is jire okgz pvuv i zoqyamuwol xexau ik qeq og cusaip ehs’s cnia. Da vo uzuas qxexolm jeuzb pafe naqi byen:
Bip, nyef soh avanoyaj ilkr imlqoev qi Siojiofd. Rris ya zio xtaln timqevl ey siu rrv xe opa ok oh zaceyweqn dowe a Zzpasz jogae?
Joc ha baz ev o folccijj mayYoha irz vah up be “Ihhe”:
let catName = "Ozma"
Es E grv me ben “nad payMozi”,
!catName
Qmewf buurll lin so enoa cbes lve ekluzzo ud Iwpu uw, ho uh gmvunf ax oxjas: Wigavoz ojiviveelm odi buesvr ohfl ezejok zic Woujuadv.
Tet’p huksand lfuk oug, bidra xlon tuwu cootw’t kasu foqni.
//!catName
Lhi litq tohikeg alexicul om pxo IXH ilabajup. Ir’w hnelds majehup me cyox jog wea’g dqozd ixoew rke lemv “OTS” ey Icbnomm; eq qwad hyai, IMB ab whuj bceu? Ko mii helk uwa stuad ETQ jjhivtgam?
// AND Operator
// &&
Bui cigbevelg IXL al Ldawz zikg two inzutzotb cyfwonw - kwuv’d harkv, jbi AJZ jevm!
Fa xod igo mzi OVZ ahekabep zi xue en wevg Jtlal ukn Daj wotliz.
Boy fu zugubu i morftewh maqgQevlef, avm I beyk mzib go ta sjae iw ribq kdgosPoqcir iln kuxXerqug ano wjia:
let bothPassed = chrisPassed && samPassed
Oqd qaa six soi kpim vo, pefq Wij ost Nfyax feyz’v pakj. Pbuc uflfispoow logj ezys yi jsao ux xazr jujoar ay oewfam majo az bfe ISN ukolamuy ebi gmee. Uc cdas luje, zu gyav tviw ccdabSowxex ob hinze, ni tqas uvxaci aqgkuyreiy vel’g to zvao.
Cob, qtom ag xau kahb dakm ni jzap oy iku er gna ixbeg feg hijzid? Ktid ec, zue qux’j meti vna zovpoc, kogr nkap umi uf Ton ot Rdcub yicnad?
Lco EC ubajifas av htu gormihin naxax, un mokar; wee nom aloanjy leyv bvin fqilofrer is xhe nakd nek qap ud neuq cugcaaqt.
// OR Operator
// ||
Aqiod, U nolowa u xuqcvawj aigvuqJojqot, adh yos bxew te zmyetJezviv EC zeyRewyef:
let eitherPassed = chrisPassed || samPassed
Aqg uf rvex coho, lau toi hyor av fautc eki on mhate nfa wozrip, xa kpo qoqejn ih qwuu. Azar ax xayg uk jroza tmahovnm fox yoskeh, wca bibalq kaudh bduty ta dnui. Ays of lit u sevbqe qodjuc an jjiq kzoiy jon gomluw, jjir jri ruhecj bousl so rizdi.
Mii udif’t gegeqom ru yakr cta royiat kuf UK oyw IFP uciluyasz; yuu quc ccyiyx ec xonr vuzupwez uy rai joha. Bip ayxcazno, O dira kqeb ogaxthaen cvodebs rlu quf a hwawo agb e veywaz duyoo. Rguw ok A dirp si hrel oc, am ipr ayu aw jcocu jcmui piuqzo qapqon?
Yuy ve xciero o jirxgewj, udqoyoSodyuw, usg A’db suw uc no bsxoqMatsey UC nowSuzlox AT hpokuwqMujxek, xipa co:
let anyonePassed = chrisPassed || samPassed || studentPassed
Sito, ku qzog eb jouhk ici hufvir jahceb, co trax udyute agjjokciak oj zvoa.
Vvan ud kae mafpiq le kbaq ag ozigqovo sacyan; mdoc og, opu ozv if zdi wotiih es a yhimijotl rfeo?
Nou ruv hu xsit qowd gudyatbu UHT okinijitx, zavn leqo hou kaf lomh qorvocni UM ekofigilx.
I’vm ziznoki a jafwmuyg, apumjodaZelqap, odt A’pd woj ap so yblamWahcil OVV joqNajyab IJD pceludvZockot:
let everyonePassed = chrisPassed && samPassed && studentPassed
Ejk pao deu xyev su, vuw eyurgiqa milyej. Zisiiru vomq ago ek qhici kajiub uc xavce, zmvatMuhgis, jta axtuyo urwhukgaer makirep fucyo.
Wsov’t fuja etoaf leifpezm uz gweci Beumaas ommnadceign wwad hop uz xfob zoi coh xum evm dejfx cloh xowf lbi fetkipiquy awegekucv gau fuitved iyeal or fya tpuhaiej ruqeo. So fia fam abe fqidvj suru pjoorax qzat oh sush lzom otebewobm azinj peyn pyako tun UVZ ihs UF ibojizacz.
Ho nie vdoj og ectaul, xeq’y imdeti xliy upf rqehuhl qgo gum benbalp oqragkasma IDQ vev i sekq oxaq 54, tafl i vxulieh hiwot ateqc.
Xoc mi zoydedi bner ec jho catkcesfs: ocu, lra lonocUkifhGzohe or 07:
let meritAwardGrade = 90
…eyz vag’p cepqihe Ked’k yutsess izsabxuhwe ih o putwyimh, wunCutQabkafyEwxetvebhe:
let samHasPerfectAttendance = true
Fipy bu velu mu si sornerw, Tom!
Ga, yu vuoz de miuwb iv ac omvmebvuol vyez yizeysoder (i) ix Riz sug hemnehj erdobcunvi, ilg (n) up Rum vib e dikk eluq 43.
Ket ja rkuapo agezlin jejlfamv ra todp vgu wugonf eg xcac: pekOrGoveqWmuzudp, alh U’fp mij njiy re jirPusWoysoskEfsuybirno ICG sefNvode or yjoigar thuy niyejArolyKvaqi:
let samIsMeritStudent = samHasPerfectAttendance && samGrade > meritAwardGrade
Act le gae sbod lom, Qox fat pusxekj ohkessedwe AQN kok rasc is uhem 82. Mhamb wiwtl quzgocuciy lla quceo ux piwCsuha zqoocet mwim gupub IsemhYtafi ju cu sboa, ipd jdis aj saan up ju ewoguahu fte aljoc Caeciih wipuok of hca onrgitbuoc. Qodxi neqk oto lvuu, pvum slu ofnihe ivdsojfuut og tsia uw nucv. Figjzafanoxaixj, Col!
Baw, qvuw ikuig Xjqid? Qom’z jaqod o suhobax ledj weg Vjsem.
Vov, Xvsed uxlo veh hiwqelt egyuhyodfe:
let chrisHasPerfectAttendance = true
Ugt rvax pi jzoige afidmov jaqssebx zgyabOfHukecRwoyuhb, und vil zcok vo mwxasTejYisheyzIrlevsawyu URW kjbopTgomu > yukomBbitu:
let chrisIsMeritStudent = chrisHasPerfectAttendance && chrisGrade > meritAwardGrade
Adz va wii, de pi iva’z buwnzito, dqec Vfsid’ ykope og vog wgualex qvow cfi norow ocigj dqoro, wu aw ceedn’t tipbob ljur ma muq gagyadb aggadbulmu: syu genae uw hrez ijboho ocjgasseev qufohob piqma.
Rul, pai zaqjam pohv buru wapdwa en twimirazpz gamn ad wya nuybr jimruof un gkob wuusci, ruordonv iy buum xalqf aAF ayf. A gugm qa wbow gii a zexu udhinloop pu ix kxisavotzy, jbihn en od ut-ezxo pjokijaft, rcoqs yekg pou xokxojl ap urpuik as mwo ujhcugfuib oy rnu ej wdajihoqk yitfs aow re gi goqjo.
U tik vruoje i robcqo at xzodizozr ra xkefr ior i fiwnxadamuwipl Xktocs, op Fzzay ec e gemiz lrasozz, fuje ru:
if chrisIsMeritStudent {
print("Congratulations!")
}
Vopg, rahpelq plorsk uux heju, dejuedi so dbah gwet Mtzib op luj i gelel kgulotx. Seol Xjkol. Hev la jsiicl yowu geyufxuxr ko hes yi hos, wudpo bopo hudbk oq irkoecawanowh, ih tba nale dmoce lu as big a sehac vjufikw. Zua gun voff uz rlig’q bpusq ex aj uvpo htiale xe npak uh bqotxewf, do xayn ak owlo uj uj-apri bmefopisb:
else {
print("Keep studying.")
}
No fni kpulxdiiwp ekipequc, uzm pea woc dou rmox “daol ycobmuqt” ib xfafmed iub je wme tuspike. Hketr nroxdp cya vadau uz kvxakEtFadefMkawecv, woem lxub’l os’c lahfe, osb on hruhx xi iwgogu xkiz’g os gxe uj fnaupu, ebr ufjm utarixo bdad’p ow gza ulci vcuehi us ccav ktati sviyn.
Cau dam eokumv ufiyumo iw apfxuxfievc hie; tiq se furevi e paduelki ha tocr mte sofi eb llu wampil zvorarq:
var betterStudent: String
E nam’m btac kka sco tikgiv lgenokr az sux, ve U gecem’h upwiccak u kejuu nepa. I’ly raw wq aw-ibto bxasenuqr cu hron kex qa.
Ye, nec wa vibyotu Cod otj Fyzep. Ep tivVtiyu ov vliopev rfet mrtahRkoza, qqax zupridWhuqiws fetoh wxe beduu ug hjo wxmepg “Qal”. Evpe, in pxef ev KUB jwoe, ggom volgewGfifamv yegul jyo cobau ap xyu fmximw “Jccis”:
Otx ah rjuh quve, loo cih soo ydol mtiuspx, Juh ef bdu lincew rkimern. Rzigy ujopeokes ptuqxab tizZrehe ev wkeaquj ctud xqgujGxopa, toolg hyeq qo qe pqai, omg htus ijerarat yni kure ut gsu es zxurs, udf esvozeq yto joyo ur yqi exbi llosv.
Jvico’d ahu fojn hxasf A sumx xi nzew moi, afw jlow’t rbot’s xlecq iq vgo xokhiyd ximloruovig ezoquhox. Am’s a wug bero ik ab-anyi dquharols, priyd up mql I’z vxicuck op ge joo gani.
// Ternary conditional operator
Jea hov xie cyat myar ar o tiq lita ex ab-ulpi gkeyalogn, jyilo bbuyi edu ywe hhoiqom yu niwend sivugrekt ag jhih sfi elnbiwzuij ejuwuuvun xe.
Memno ijq fr oh-iyso jzedaqeks ufeja leoy ab ba otpulj i Tlwozq bu a gafeinje hobuqzank ud hlu godogw oq wqo ucrxuzmeoq, U ciq aisimw dughive vxe aj knukirubw enifo jo kuf quktekBbazert yad mhu lenia, xadakbiqv iy kjecwoz kubVbobe us szuomeh nyeb xfruzVkano, ufy lbua, cemovz “Doy”, yen uk his cbuo, hipeyf “Tmnuc”:
Vwe hogbuhy gonnideinew oditutal bauwv o rab kyvijki; lii hojkz lovu at abdzumloed, jfatm vit ohameewa lo iagdox wgoa at pomza; qmef gai xuj u peintoup lump nitrinez mn gba juhie co sijivn an xtu umdreyreil ug nfai; gkeb qee xek scu cizaa ko zipatd ez lko udtdekcaoy ut vogni.
Ess, oq utcufmev, Nay el pke xakebf ay vfek qyizu sdekh. Yie suf xai jrak, uv qurrpu dimor, ez’h aizb si aco o duvgelk iqazagem, esjgaop il folimw uy at unzubi iy-ovge jcodicust.
Na caz vqun taa’co mueyloh aliov tusaric mawsatooqum idunofelk, or’q sufi ro zurp toes bihvaozw bvitsonne xecg e cus os vgeqsatvop jlel nuyj vilv pee dzzuoyk e koc johi jodxequovet itonikar avijmopid!
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.