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

Angela Don
Angela Don
613 Points

I cant figure this one out? let totalScore == 10

Not sure how to set true value to the number in the question

operators2.swift
// Enter your code below

var initialScore = 8 

let totalScore = ++initialScore + 1

let isWinner = totalScore

let totalScore == 10

3 Answers

Task 1: The constant initialScore (provided) is the players current score. Add 1 point to their score using the increment operator and assign the result to a constant named totalScore.

let totalScore = ++initialScore

You don't need the +1 since that is what the increment operator - "++" - does.

Task 2: 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 to it.

let isWinner = (totalScore != 10)

which is a simpler way than using an if else statement. Don't use this in the challenge, just a way to see the logic behind.

var isWinner: Bool = true

if totalScore != 10 {
isWinner == true
} else {
isWinner == false
}
Jhoan Arango
Jhoan Arango
14,575 Points

Hello :

  • Challenge

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)

So the challenge is asking you to declare a constant named isWinner and assign the results of a comparison operation.

Therefore, you want to do an operation where it compares something, and then that value is giving to the constant we want to declare.

Here is what you want to do:

var initialScore = 8
let totalScore = ++initialScore 

// Here we are saying, if totalScore is not 10, then is winner.
let isWinner = totalScore != 10 

Hopefully this helps you move on with your challenge.

Good luck.

var initialScore = 8 initialScore += 1 let totalScore = 10 let isWinner = initalScore !=10