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 trialKelsey Curran
381 PointsNOT Operators
Not sure what I'm doing wrong... is there a simpler way to get what they're looking for here?
It prints what they want, but I think I'm adding an unnecessary step.
// Enter your code below
var initialScore = 8
initialScore += 1
let newScore = initialScore == 10
let isWinner = !newScore
1 Answer
andren
28,558 PointsYou are indeed adding an extra step. You can reverse the initialScore == 10
operation without creating a separate variable by wrapping it in parenthesis like this:
var initialScore = 8
initialScore += 1
let isWinner = !(initialScore == 10)
By wrapping the comparison in parenthesis you tell Swift to complete the comparison first and then to invert the result with the ! operator.
That is the solution the challenge hints at. Though honestly it's not that common to see code like that in the real world in my experience. It's more common to use the not equal to operator like this:
var initialScore = 8
initialScore += 1
let isWinner = initialScore != 10
That does the same thing but is a bit simpler to read. Both of those solutions will work for this challenge.