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 Basics Swift Operators Working With Operators: Part 2

Clifton Blair
Clifton Blair
2,108 Points

How to make isWinner = True

How do I get to my answer?

operators.swift
// Enter your code below

var initialScore = 8

initialScore += 1

var isWinner = 10

let isWinner = true

let isWinner = !isWinner
Steven Beckham
seal-mask
.a{fill-rule:evenodd;}techdegree
Steven Beckham
iOS Development Techdegree Student 2,979 Points

The value of isWinner should be a comparison operator that checks to make sure initialScore is not equal to 10. You'll be using

!=

Make sure you only declare isWinner once. Right now you've declared it three times.

Are you typing your code in Xcode first? Writing in a playground really is helpful for catching a lot of mistakes that you may overlook if you're trying to write code directly in the browser.

Clifton Blair
Clifton Blair
2,108 Points

I was not inputing the code into Xcode.

1 Answer

andren
andren
28,558 Points

isWinner should only equal true if the initialScore is not equal to 10. Let me rephrase the challenge a bit, say you had an if statement and were asked to write a condition that would make it run only if initialScore was equal to 10 how would that condition look?

Well it would look like this initialScore == 10 and here is the thing, comparisons like that can't just be used in if statements and the like, you can assign the result of those comparisons (which is a boolean) directly to a variable like this:

let isWinner = initialScore == 10

That code will result in isWinner being true if initial score equals 10 and false otherwise.

You can negate (reverse) the result of that comparison either by using the ! operator like this:

let isWinner = !(initialScore == 10)

Or by using the not equal to != operator like this:

let isWinner = initialScore != 10

Both of those examples will result in isWinner being true only if the initialScore is not equal to 10. Which is what the task is looking for.