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

Ingo Ngoyama
Ingo Ngoyama
4,882 Points

On the second task of the Operators Quiz for swift are we supposed to use an if statement. we have not been shown that.

this is the question: 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)

operators2.swift
var initialScore = 8
initialScore = initialScore + 1
let totalScore = ++initialScore 



x != 10
let isWinner = result

5 Answers

Ingo Ngoyama
Ingo Ngoyama
4,882 Points

Thank you. That fixed it thanks man. I am good with C# and HTML5 so let me know if you ever need help :)

Moritz Lang
Moritz Lang
25,909 Points

Hey, the task is to assign the result of a comparison to a constant named isWinner, not to write an if statement. The solution for this task should be the following:

let isWinner = totalScore != 10

Here you assign the return value of totalScore != 10 to the constant. If totalScore is not ten, the return value would be true. Otherwise it would be false.

Hope this helps :)

Ingo Ngoyama
Ingo Ngoyama
4,882 Points

Thank you, tried that and I got this: Bummer! Make sure you increment the value of initialScore just once

Moritz Lang
Moritz Lang
25,909 Points

Sorry that I didn't get this in my first answer :) You increment initialScore two times. 1. initialScore = initialScore + 1 updates initialScore and assigns the new value back to initialScore. 2. let totalScore = ++initialScore increments initialScore and assigns the value to totalScore. The second one has one crucial side effect: It increments initialScore first and then assigns it to totalScore. Because of that initialScore has also been updated. If you remove the first incrementation you should be fine.

Moritz Lang
Moritz Lang
25,909 Points

Sure. Thanks in advance :)