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

Mads Thorsen
Mads Thorsen
3,464 Points

Hi, how do I assign the result of the comparison and not just the boolean value? Thx

I dont have a problem with the code, It seems like I just dont get something really simple!! I have made the comparisons in my Playground, so I know what is the correct answer.

Thanks alot

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
let isPerfectMultiple = result == 0

// Task 2 - Enter your code below

let result2 = anotherOperation>=someOperation
let isGreater = true == result2

2 Answers

Hi there,

You just need to combine your two lines of code!

You've got the comparison (nearly, its the other way round :wink:), someOperation >= anotherOperation.

Now, just assign that result (which will be true or false) into the isGreater constant:

let isGreater = someOperation >= anotherOperation

I hope that helps.

Steve.

Mads Thorsen
Mads Thorsen
3,464 Points

Thanks alot it worked :) But am I totally off thinking that the value of anotherOperation is 7 and someOperation is 5.!! Or am I just really tired and confused :)

Mads Thorsen
Mads Thorsen
3,464 Points

Oh it doesn't matter if it's true or false :) False just lets me know that it isn't greater, appreciate the help. Thanks alot...

Tired and confused, I'll go for! :smile:

The comparison isn't a statement of fact. It's a test - it is irrelevant what the two operations calculate out to - it wasn't expected that you work it out!

The test is just saying is the result of one operation bigger than the other. The answer is true or false - that's what gets stored in the isGreater constant. This isn't about actual values - the two operations are supposed to represent two unknown values; we're using code to test which one is larger.

The question asks that you store the result of comparing someOperation to anotherOperation and store the result of that comparison (using greater than or equal to) in the constant isGreater. So that's all that needs doing.

By way of example, in some courses the starter courses will ask you to store your name in a String instance. It isn't wrong to store any name/string in that so, (Java here) String firstName = "Steve"; is valid code for the challenge for me, or for you.

Similarly, (Java again) int age = 21; while a complete lie, for me, is still valid code. It followed the instructions. "Store an integer representing an age in a variable called age".

Here, we're just comparing two things that are supposed to remain uncalculated and storing the value of that comparison in isGreater. The fact that one is greater than the other doesn't mean we're seeking to store the value true in the constant. The answer false isn't wrong, it is simply a statement of reality. someOperation is less than anotherOperation - so isGreater is false. That's all we wanted to know.

I hope that helps; shout me if not.

Steve.

You got there just fine! :smile:

Good work. :+1: