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
Cesar Gonzalez
614 PointsHaving trouble with the Not Operator in Swift Basics last challenge, please help! https://teamtreehouse.com/library/swif
Help , Thanks . Question asks to ((((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))))
var initialScore = 8 let totalScore = ++initialScore ///question let winTen = !true let otherNumber = true let isWinner = true
3 Answers
Unsubscribed User
24,880 PointsYou'd have to declare a constant named isWinner first, so:
let isWinner =
and then it's telling you that if totalScore DOES NOT EQUAL 10, then isWinner is true. The question is looking to get a boolean value for the constant isWinner, so it should evaluate to true because totalScore is holding the value 9.
let isWinner = totalScore != 10
Essentially it means: 9 != 10 and this is true
Cesar Gonzalez
614 PointsThanks man it help me a lot to understand the task i didnt know i could write a piece of code like that anyways thanks bro!!
Cesar Gonzalez
614 PointsJake Adams
1,608 PointsOk, using hardcoded values like setting the initialScore to 8 can cause confusion in a scenario like this. Our goal is to come up with code that will behave as we expect even when we don't know the initialScore. So for our purposes, let's pretend we don't know the value.
You have the increment correct, so the only thing we know about totalScore is that it is at least 1. We also know that the losing score is 10. To make this easier to read, I would recommend setting a constant
let losingScore = 10
What we want to do now is compare the totalScore to the losingScore. If they are not equal, then isWinner should be true. The goal of this task, though, is to not use the keywords true and false directly. What we're looking for is an expression that will result in either a true or false value.
Tip: == is the equality operator that is checking to see if 2 values are equal. To check if 2 values are not equal, you need to use the not equal operator: !=
let isWinner = <compare totalScore to losingScore here>
Hope this helps!
Cesar Gonzalez
614 PointsThank you bro it did helped me!!
Jake Adams
1,608 PointsJake Adams
1,608 PointsCan you provide a link to the challenge so I can take a look?