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 trialJoey Shiner
8,372 PointsNOT operator
In my challenge, I am designing a game where if the score is exactly 10 you lose, if it is anything but 10 you win. I am required to declare a constant named isWinner and add the results of my comparison operation to that constant. I am to use the NOT operator, yet when I use it with integers it says i am making an error. How do i tackle this challenge without using the NOT operator on the number 10?
// Enter your code below
var initialScore = 8
let totalScore = ++initialScore
let isWinner = !10
1 Answer
Tobias Helmrich
31,603 PointsHey Joey,
you have to use the not operator on a boolean value but you're using it on a number. Besides that you're not comparing the totalScore of the player to anything so you can't really check if the player has won or lost.
One way to solve this task would be like that:
// Enter your code below
var initialScore = 8
let totalScore = ++initialScore
let isWinner = !(totalScore == 10)
In this case we're comparing the value of totalScore to 10. If the totalScore constant has the value of 10 it will evaluate to true and because the player loses if he has a score of 10 we now have to turn this to false using the not operator.
I hope that helps, good luck! :)