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 Basics Swift Operators Working With Operators

Step 2 Question

Not sure if I am doing either step correctly. How do you compare a value then assign it to a constant? Do you set up the comparison first, then assign it, or can you assign it if it pass the true false test?

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
let isPerfectMultiple = result == 0

3 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Todd,

You have everything correct, except for the mathematical part to get the remainder. To find the remainder, you use the Modulo operator (%), but you are using the division (/) symbol (but have the % at the end?)

So this line,

let result = value / divisor %

Just needs to be corrected to assign the remainder to the variable result like so

let result = value % divisor

Hope that helps. (The rest of your code is correct :thumbsup:)

Keep Coding! :dizzy:

Thomas Dobson
Thomas Dobson
7,511 Points

Todd,

You got it mostly right. Your remainder syntax is incorrect. Try this:

// 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 //result equals zero because no remainder is present.
//For example: If it was 201 % 5, result would be equal to the remainder of 1.

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

See the Remainder Operator section of the Apple Operator Docs

I hope this helps.

Jason and Thomas,

Thanks - that makes sense.