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


#1

https://www.codecademy.com/courses/learn-javascript/lessons/control-flow/exercises/logical-operators

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
http://joxi.ru/xAeLvMRsY3jEa2
and my version of the code:

var moonPhase = 'full';
var foggyNight = 'true';
if(moonPhase === 'full' && foggyNight) {
  console.log('Howwwwlll!');
} 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?


#2

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.


#3

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.


#4

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.


#5

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?


#6

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

#7

Soooo.... where's exactly my mistake and how should I fix it?


#8

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.


#9

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