wereWolft.js Exercise


<Hey guys, I’m stuck at this javascript exercise (wereWofl.js)…>


<Now, when the variable moonPhase is full, I expected the first block code to run since moonPhase === ‘full’. But instead it is logging the else statement to the console. What could be wrong?.>


var moonPhase = ‘full’;

if (moonPhase === ‘full’ && foggyNight === false) {
} 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;

<do not remove the three backticks above>

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.

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.

Did you move the foggyNight variable declaration?

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

Im having the same problem.
The first question says:

Write a variable named moonPhase and set it equal to ‘full’.

my awnser was:

var moonPhase = full;

the second question was:

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) {
} else {
console.log(“I swear I am not a werewolf”);

what am i doing wrong?

kind regards

Filipe Serrano

set it equal to ‘full’.

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

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