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.

Why should I use the "NOT operator" (`!`) here?

I'm not quite sure why I'd use the "NOT operator" in this challenge. The way I've solved it seems to produce correct results, but the automated grader complains, "Bummer! Make sure you increment the value of initialScore just once" and the hint says "Use the NOT operator" so thought I'd post here to see what's up.

4 Answers

the totalScore is 9 not 10 so the player is not a winner! In the game if you have anything other than 10 you lose so you need to check if totalScore is anything other than 10 using != meaning isWinner is false.

I selected the option to attach my solution to this post, but I don't see it here so I've included it below.

```var initialScore = 8
let totalScore = ++initialScore
let isWinner = totalScore == 10
```

the totalScore is 9 not 10 so the player is not a winner! In the game if you have anything other than 10 you lose so you need to check if totalScore is anything other than 10 using != meaning isWinner is false.

```let isWinner = totalScore == 10
```

Hm, why would I use `!=` for this? In the example code I've included above, `isWinner` will be `false` because `totalScore == 10` evaluates to `false`. I would use `!=` if the condition was `notWinner`. If you really want to use `!=`, you can do

```let isWinner = !(totalScore != 10)
```

or

use an if (totalScore != 10)/else block

... but that just seems overly complex compared to what I have above :P - Am I misreading the question, or is the solution I've provided not logically correct? It provides the correct result so not really sure what I'm missing. I suspect this is an issue with the challenge's grader.

The code challenge states: "At the end of the round, if your score is 10, you lose! If it's anything but 10, you win."

```isWinner = totalScore == 10
```

result would be false because 9 does not equal 10, but the player should be a winner.

```isWinner = totalScore != 10
```

result would be true because 9 does equal "not 10", so they are a winner, which is the result we are expecting.

Ah misread too many times-- my bad. Thought it was if it's 10, you win :P