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 trialDaniel Bakh
141 PointsComparison operations and bool values
What is wrong with this code?
// 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
result == 0
let isPerfectMultiple = false
someOperation <= anotherOperation
let isGreater = false
2 Answers
Martin Wildfeuer
Courses Plus Student 11,071 PointsHey there! Let's go through this step by step:
"Using the remainder operator, compute the remainder given the value and a divisor. Assign this value to a constant named result." You are using division instead of remainder
// Task 1 - Enter your code below
let result = value / divisor
Make sure to use the remainder operator, explained in detail at Apple Docs.
"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 comparisons are on single lines, which does not affect code and only makes sense in playgrounds. Moreover, you are directly assigning fixed booleans to the constants, without the logic requested.
// Task 2 - Enter your code below
result == 0
let isPerfectMultiple = false
someOperation <= anotherOperation
let isGreater = false
Make sure to assign the result of your comparison (a boolean) to the constant like in this example:
let result = oneInt == otherInt // true iff oneInt == otherInt, else false
Hope that helps :)
Daniel Bakh
141 PointsHi,
Thanks for the help !