Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBea Santos
iOS Development with Swift Techdegree Student 427 PointsI 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
// 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
Front End Web Development Techdegree Graduate 84,738 PointsYou'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
.