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 2.0 Basics Swift Operators Working With Operators

Joey Shiner
Joey Shiner
8,372 Points

bool value

how do i assign the results of a comparison operation without using just a bool value?

operators.swift
// Enter your code below




// Task 1 - Enter your code below
let value = 200
let divisor = 5
let result = value % divisor

0 == 0

let isPerfectMultiple = true

// Task 2 - Enter your code below
let someOperation = 20 + 400 % 10 / 2 - 15
let anotherOperation = 52 * 27 % 200 / 2 + 5

someOperation >= anotherOperation

let isGreater = false

2 Answers

Joey Shiner
Joey Shiner
8,372 Points

Thank you so much!!!

Glad I could help! If this answer has helped you please mark the answer as correct so others can benefit from it! Thanks and good luck learning!

Since a comparison can only be true or false, that is the only thing it can return

someOperation > anotherOperation // can only be true or false

If you were looking to return the value from one of the operations based on the comparison you would need to use a conditional block

if someOperation > anotherOperation {
  return someOperation
} else {    // else portion is not required if you only care about someOperation
  return anotherOperation
}
Joey Shiner
Joey Shiner
8,372 Points

Yes, thank you, but the challenge reads "Without computing the values of those operations, we'd like to know if the first operation, someOperation is greater than, equal to, or less than anotherOperation. Use the greater than or equal to operator and assign the Boolean result of the comparison to a constant named isGreater."

so I did as the challenge requested, but now it is marking my answer wrong and saying "Make sure you're assigning the results of a comparison operation to isGreater and not just a Bool value"

I am unsure of what this means or what they are looking for in this answer.

Oh. I understand your question now. So currently you are just evaluating the comparison. You need to assign it to a variable. For instance:

let isGreater: Bool = someOperation >= anotherOperation // This will evaluate and assign the result

You can leave out the : Bool part and Swift will infer the type, but I recommend in the beginning explicitly typing your variables.