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

How do I assign the Boolean result to a constant named isGreater?

let someOperation = 20 + 400 % 10 / 2 - 15 let anotherOperation = 52 * 27 % 200 / 2 + 5 "someOperation" >= "anotherOperation" let isGreater = true // <----- this is not working

operators.swift
// Enter your code below
let value = 200
let divisor = 5
let result = value % divisor
let isPerfectMultiple = true

let someOperation = 20 + 400 % 10 / 2 - 15
let anotherOperation = 52 * 27 % 200 / 2 + 5
"someOperation" >= "anotherOperation"
let isGreater = true 

// Task 1 - Enter your code below

// Task 2 - Enter your code below

2 Answers

Steven Parker
Steven Parker
231,269 Points

You should not assign a boolean constant.

It apparently let you get away with it on task 1 when you assigned isPerfectMultiple, but both that one and this one should be assigned with the result of a comparison operation.

I'm sorry, but that just confuses me even more. How did I "get away with it" on the first one? can you provide any examples?

Steven Parker
Steven Parker
231,269 Points

For Step 2 of task 1 you were supposed to assign isPerfectMultiple with the result of comparing value to 0. But instead you just assigned it to true. The challenge apparently accepted that answer but it should not have.

Thanks, Steven. I was able to go back and fix everything. I appreciate the help.

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

So Luke,

You've seem to gone a bit off track here. Right now you're trying to compare two strings and hard-coding boolean values into constants. In the first case, you will want to compare the constant's value, not the name of the constant as turning them into a string will do.

In the second situation, the comparison of the values needs to be done in the actual assignment of the asked for constants.

There are many incorrect lines in the code above, so restart the challenge from the beginning...

You have task #1 correct, just not in the right place in the challenge. Again the challenges are very picky, so that line will need to go under the "// Task 1 - Enter your code below" line.

Now for task #2

Step 2: When value obtained using a remainder operator is 0, this means that the value is a perfect multiple of the divisor. Compare the value of result to 0 using the equality operator and assign the resulting value to a constant named isPerfectMultiple.

The comparison of the result constant to zero will be done in the assignment of the isPerfectMultiple constant. This will only require one line. It will start off with isPerfectMultiple = and then the comparison. Remember when comparing two things to see if they are equal, you use the double equal sign ==.

Keep Coding & Keep Learning! :dizzy:

Edit: Removed last paragraph, as it pertained to another profile looked up by mistake. I see the track mentioned in said paragraph was completed. My apologies for the mistake.

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

On another note:

Please do not post multiple threads for the same challenge/topic/question to the Community.

With the exception of this one, I have deleted all other posted threads regarding this topic.

Jason Anders - Treehouse Community Moderator