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

code

whats the error in my code?

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 = 5 / 200 = 0
// Task 2 - Enter your code below
let isPerfectMultiple = "\(result) > 0"

1 Answer

J.D. Sandifer
J.D. Sandifer
18,813 Points

I'm guessing you're on step one. Assuming that, here's what's up:

  1. You have an error in syntax - probably just a typo. The = assignment operator is used for assigning values to variables or constants like this: let aConstant = 1. You have it twice in one line which doesn't work because the second one creates this expression 200 / 5 = 0. You can't assign a value to a calculation. Start by removing the last two characters on that line and your code won't have any compilation errors. However...
  2. Your task is to assign the remainder of dividing value (not 200) by divisor (not 5). Using the variables or the values might not even matter, but you're supposed to get the remainder - not do division - and you have the order backward. Hint: % is the operator you want for that first task.
  3. Finally, the second task is to assign a comparison - whether result is equal to 0 - to isPerfectMultiple. The goal is not to create a string (what you're doing now), but to create a comparison that gives a true or false value. You'll want the == equality comparison operator for that.