5. Slaying the dragon, What's wrong with my code?


I'm not entirely sure what I did wrong. I'm quite new to javascript, and no matter what I do I can't seem to get this to work. It says I'm not logging the message to the console?


If you look at the error in the console, it's saying 'youHit is not defined'

Now there's the problem - at the start of your code (lines 3-7) you're using a comparison operator (===) when you're supposed to be using an assignment operator (=).

=== is used to compare the value and type of two operands.


That solved the problem. I hadn't really been paying a lot of attention to those before since I get them mixed up easily. I'm still new at this so thanks!


Glad it worked!

Just for reference:

x = y: assign x as y
x == y: return true if x has the same value as y
x === y: return true if x has the same value and type as y

The difference between the last two is that, for example, the integers 0 and 1 can be used as the booleans true and false respectively.

So if x was 1 and y was 'true':
x == y would return true because their values both equate to true or 1.
But x === y would return false, because 1 and true are not the same type (as 1 is an integer and true is a boolean).


I didn't know that that was how they worked. Thanks for helping me, I'll be sure to remember it!