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

Kelly Sullivan
Kelly Sullivan
412 Points

Stuck on task 2 of Swift 2.0 Basics Challenge, Unary Operators

This is the task... "In this game of ours, we have an odd scoring mechanism . At the end of the round, if your score is 10, you lose! If it's anything but 10, you win.

Declare a constant named isWinner and assign the results of a comparison operation to check whether the player has won or not. If the total score is not 10, then the player has won, otherwise he or she has lost. (Hint: Use the NOT operator)"

I'm not sure how to write the comparison operation

operators2.swift
// Enter your code below

var initialScore = 8
let totalScore = ++initialScore

let isWinner = true
isWinner != 10

4 Answers

The challenge title is a little confusing, but try this:

var initialScore = 8
let totalScore = ++initialScore
let isWinner = totalScore != 10
Kelly Sullivan
Kelly Sullivan
412 Points

Thanks! I think I was overcomplicating it. This works and now that I look at it, it makes perfect sense. Thanks for the quick response!

Hmmm, so you can use:

var initialScore = 8
let totalScore = ++initialScore
let isWinner: Bool

if(totalScore != 10){
   isWinner = true
}else{
   isWinner = false
}
Anthia Tillbury
Anthia Tillbury
3,388 Points

I did the following for pt.1, what is wrong please?

var initialScore = 8
var totalScore = 1


if totalScore > 0 {
    totalScore + 1
    initialScore = initialScore + totalScore
    totalScore = initialScore
}
Anthia Tillbury
Anthia Tillbury
3,388 Points

For the second answer I used the following code:

var initialScore = 8
let isWinner = 10


let totalScore = ++initialScore


if isWinner != 10 {
    print("You Won!")
}

else {
    print("You Lost!")
}

Again, it's not accepted, how come?