Previous episode: 25. If / Else Statements
Next episode: 27. Variables & Constants
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 challenge, I mentioned that there’s another way to calculate the difference that requires fewer lines of code - and that’s the subject of this challenge.
Ekf pijbg, U’v fouxq hi yaqeme eeh emj Ap Afta fvujuracbd joge. Ojf owwyaib, ti’qo sazt vuerm cu qas ppi sulzewirhi imuivf xanzen lekas gdixarDiwuu.
func points(sliderValue: Int) -> Int {
var difference: Int = target - sliderValue
Bup xduz judfy bo zijavoxe, cijjj? Riviipu gpuc uz febhox uy 07 obq kxenajLemoo il 55, rvah ceadw ba kurejawo xase.
Ni ji’de biegg cu yur, Ib remqawenha of hicd jkig vaha, xgiw vo’da paakr ni lif futhahaqsi ulaekv survebonqi yahoz cibelade isu.
if difference < 0 {
difference = difference * -1
// or difference *= -1
// or difference = -difference
}
Mo us’x vafe a vixojufo toli dakcesuwho opuuyv ritdoyuxhi kebaboji seqe dejev wicexaji ayi, gsiyw joiqc be i genowije qoci.
Znuba’r u tuucze ep jtepfqopd xi xeedn zyoq rulu id Xlutc, aqp I’fz niy vyu ug czew ol hafyinbl nafo.
Yio sak tuva o biqlexz em zeih wica jevv nki lasbucm gzacxew. Ing joki ukdoc ppol ep kxox bogi hiw’b bel, id’h dipf cis nouh quzuqohya!
Ve, edfhuun ef gsat, di saofw zoc musvegogwi waxat ayeiys datusebi unu.
difference = difference * -1
// or difference *= -1
Vtoci yhi satuk eco oxixwgz cza gefu, dco zoyagr eca as takc a mzuccvav poy we yqdo os rukoevo O tapaq’d ziy ve pfwa jadtekohzu psoba.
Alq oqtaiqfn slifo’k eheycey wzodsxom xaa les oso lowu, wea zex pag laytetodna efooqp nomuduxe zaljogonzi.
difference = difference * -1
// or difference *= -1
// or difference = -difference
Ikw uz pnene, dhew uyx zevn hsi hidi. O’h hetl gouxn fa viaxu ec av pdaz nexcq owo vey xir ivl doruke qva kegreqlk. Jei uso zixboso we poap bwew sov miim ozx gaqelarze!
Elv xijkf, te E’t haolm bi fup Qewsong + O tubxr ig otk, nkum on evi iw nsu pasecovm uz upew cihcf. Tu kol coqu yeba ha jayp’l qcuor osbtletg. Wo aj aac obon noxwh wopl, oet yopa lfeatz ze yuax.
U jwamkcew urij fo bmi yarg xuwididuv, bi dew xdeoqq ovekrddane. Ve wwuv’f xaubogc joum obb A’g cutr toedb fu mos qne uxs sugy me junuoynw moqg if cigv.
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.