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 Assignment and Comparison

Need help with task 2 Is there a glitch by any chance?

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

someOperation >= anotherOperation

let isGreater = true

Any reason why this is not working

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Richard Cho ! No, this is not a glitch. First, you may not remove the passing code from Step 1 of the challenge. Doing so will cause Step 2 to fail, even if the code for step 2 is correct. These tasks are cumulative. Never remove code from the previous task unless explicitly asked to do so.

As for your second task, you are hard-coding the isGreater to true. You're simply assigning the value of true here. But what if in our program the value of someOperation and anotherOperation are constantly changing (let's say they are variables instead of constants)? You wouldn't be able to guarantee that isGreater should be true at any given time. Right now, you are performing an evaluation between the two and that code is running. But the results of that evaluation are just sort of floating out in limbo now. They were neither displayed nor were they saved. The challenge asks you to save the results directly into the constant isGreater.

We can do that like this:

// someOperation >= anotherOperation is evaluated to either true or false
// the true or false will then be stored in isGreater
let isGreater = someOperation >= anotherOperation

Hope this helps! :sparkles: