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: Part 2

Unable to complete this quiz, help!

The only error I get is "Bummer! Try again!" and I can't think of anything else to change or put in.

As you can see I even went further with the assignment to check if that was what I was missing. I feel so useless at this stuff sometimes! Haha

  • Rob
operators2.swift
var initialScore = 8
let totalScore = ++initialScore

let isWinner = totalScore
totalScore != 10

if totalScore <= 10 {
    print("You won!")
} else {
    print("You have not won!")
}

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Robert,

I feel you may have been overthinking this challenge, and you're correct in that you add more than what the challenge asked for. Keep in mind, if you add more than what the challenge wants, you usually will get the "Bummer." Challenges are very specific and extremely picky. :)

As for the question, the answer is really just one line of code. While it looks like your code will return the same result, there is no need for an if/else statement. You can do the comparison right in the assignment to the new constant. By putting in a comparative statement into the assignment, it will either evaluate to True or False.

So all you need (and I'll include the code for your reference). Have a look and if it doesn't quite make sense, be sure to review the video before moving on.

var initialScore = 8
let totalScore = ++initialScore

let isWinner = (totalScore != 10)  //this will assign true or false to `isWinner` based on the value of `totalScore`

Note: the comparison is checking that totalScore does NOT equal 10.

Keep Coding! :) :dizzy:

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

Oh, and just an FYI. The Unary operators ++ and -- have been deprecated in Swift 3. So, if you are working in a local development with the latest version of Xcode, the above code will return a syntax error.

I greatly appreciate your help!

Trying to finish this quiz has been the source of some frustration for quite some time! Haha

Kind regards,

  • Rob