Learn JavaScript / Control Flow / Step 6. Werewolf.js


<Below this line, add a link to the EXACT exercise that you are stuck at.>

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
The task is in the following: “We already have a moonPhase variable, so let’s start with making a foggyNight variable set equal to true.” I did it, but nothing changed, except an error :frowning:

Here’s a screenshot of that problem
and my version of the code:

var moonPhase = 'full';
var foggyNight = 'true';
if(moonPhase === 'full' && foggyNight) {
} else if (moonPhase === 'mostly full') {
  console.log('Arms and legs are getting hairier');
} else if (moonPhase === 'mostly new') {
  console.log('Back on two feet');
} else {
  console.log('Invalid moon phase');

Can anyone help me? I’ve already read about other people’s problems with that exercise but there was no solution. Is that really or bug?

When you set the variable for foggyNight, you’re using “true” which is a string, not a boolean. If you use true, then when you check foggyNight, it will come back as true.

1 Like

I suppose you’re wrong. Boolean has two values (usually denoted true and false), and string is the text (which expresses the value) in single or double quotes.
More than that, the task itself says “set variable equal to true”. I did exactly so.

var bool = "true"

Is not the same as:

var bool = true

Any ‘real’ value will come back as true if you check like that. You could type “false” instead of “true” and it would equate to true because there’s a real value.

1 Like

But it’s all about variables, not the booleans! Here we add different variables in order to get learn its multiple types. Am I wrong?

The lesson that you posted is about logical operators with are at the most basic level checking to see if one thing and/or another thing is true or false.

Just like the operators we learned previously, these logical operators will return either true or false.

These logical operators are helpful when writing if/else statements, since they let us make sure multiple variables are true or false.

I don’t know if this will help, but:

true && true //will return true
true && false //will return false
true || false //will return true
false || false //will return false
!false //will return true
!true //will return false

Soooo… where’s exactly my mistake and how should I fix it?

Well I finally found the mistake. The meaning of the variable should have been between the parentheses, like this:

var foggyNight = (true);

After I corrected it, everything was fine and I was able to continue the lesson.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.