wereWolft.js Exercise


#1

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


var moonPhase = 'full';

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

var foggyNight = false;


#2

We don't see the question that would logically accompany a post such as this. May we assume the lesson is not passing the SCT? That would be due to an undefined variable error being raised since the above variable is not defined until after the if statement.

Move this line to where the other var is declared.


#3

Oh sorry, I still don't understand how to format my post properly yet. Since its my first.

But the problem is that the first block of code is supposed to run since it met the condition of the statement.

But it keeps running the last block of code which says 'invalid moon phase'. Why? Its not like the value for the variable is undefined.


#4

Did you move the foggyNight variable declaration?

Have you learned yet how to toggle a boolean? That would be handy in this instance.


#5

Im having the same problem.
The first question says:

1.
Write a variable named moonPhase and set it equal to 'full'.

my awnser was:

var moonPhase = full;

the second question was:

2.
Write an if/else statement that checks if the moon is full. If the moonPhase is 'full', log 'Howwwwlll!!' to the console, and if it is anything else, log 'I swear I am not a werewolf...'.

My anwser was:

var moonPhase = full;

if (moonPhase === full) {
console.log("Howwwwlll!!");
} else {
console.log("I swear I am not a werewolf");
}

what am i doing wrong?

kind regards

Filipe Serrano


#6

set it equal to 'full'.

Note the quotes on the string. Same applies to step 2.


#7

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