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

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,624 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: