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

Why is this wrong? It runs fine in playground. Preview doesn't show output errors

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

if result == 0 { let isPerfectMultiple = result print(isPerfectMultiple) } What is let someOperation and let anotherOperation for it isn't in the question. It runs fine in playground.

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

if result == 0 {
  let isPerfectMultiple = result
  print(isPerfectMultiple)
}

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

Hey Robert,

While you're on the right track and the above code is correct in syntax, I feel you may have misinterpreted the instructions a bit as to what the challenge is looking for.

Step two wants the result of the comparison assigned to the variable, not the value of the result variable. This assignment will be a boolean value depending on if the result is a "Perfect Multiple" or not.

Right how, with the if statement, you are checking for a "Perfect Multiple" and then assigning the value of result to the isPerfectMultiple variable instead of the boolean value of the comparison itself.

So you will start with the declaration let isPerfectMultiple and assign the value of the comparison (result == 0). It will look a little strange if you're new to coding, but when you put the two together, you have:

let isPerfectMultiple = result == 0

I hope this helps to clear things up for you.

Keep Coding! :) :dizzy: