Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift Basics Swift Operators Working With Operators

Bea Santos
seal-mask
.a{fill-rule:evenodd;}techdegree
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
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,696 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.