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 trial

iOS Swift 2.0 Basics Swift Operators Working With Operators

Check if a value can be divided perfectly without any rest

This would not be compiled although it works in my xcode playground

2 Answers

Hi Daniel,

The first task results in code looking like:

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

Here we have used the mod operator to assign the result of value mod divisor into the constant result. Then we test result to see if it is zero, and assign the resulting boolean (true/false) into the constant, isPerfectMultiple.

I'll post the next task in a second ...

Steve.

The second task uses the two operations already defined in the workspace - one is called someOperation and the other, imaginatively, is called anotherOperation. The challenge is to compare them to see if someOperation is greater than anotherOperation. The result of that comparison needs to be stored in another boolean constant called isGreater. To compare them we use the greater than symbol, like this:

let isGreater = someOperation > anotherOperation

And that completes the challenge!

Steve.