iOS Swift Basics Swift Operators Working With Operators

Bea Santos
Bea Santos
iOS Development with Swift Techdegree Student 427 Points

I don't understand the second code challenge of the operators section.

// Enter your code below let value = 200 let divisor = 5

let someOperation = 20 + 400 % 10 / 2 - 15 let anotherOperation = 52 * 27 % 200 / 2 + 5

// Task 1 - Enter your code below let result = value % divisor

// Task 2 - Enter your code below result == 0 let isPerfectMultiple = true

someOperation >= anotherOperation thatResult = false let isGreater == thatResult

operators.swift
// Enter your code below
let value = 200
let divisor = 5

let someOperation = 20 + 400 % 10 / 2 - 15
let anotherOperation = 52 * 27 % 200 / 2 + 5

// Task 1 - Enter your code below
let result = value % divisor 

// Task 2 - Enter your code below
result == 0 
let isPerfectMultiple = true


someOperation >= anotherOperation 
thatResult = false
let isGreater == thatResult

1 Answer

Brendan Whiting
MOD
Brendan Whiting
Front End Web Development Treehouse Moderator 84,129 Points

You're "hard-coding" the answer now by assigning a boolean value to the variable. It's the correct value given the numbers that we have above, but what they want us to do is have the code produce the boolean value in a way that would still work with different numbers. That way we could build a block of code that's more generic, could be used with other numbers, run it through some logic, and maybe produce a result depending on what numbers are passed in.

let isPerfectMultiple = result == 0 
let isGreater = someOperation >= anotherOperation

In this code, result == 0 might return true, or might return false. But we know it will assign a boolean value to isPerfectMultiple. Similarly, someOperation >= anotherOperation might return true or false and will assign the boolean value to isGreater.