JavaScript: Control Flow 7/11 else if Statements


#1

I cannot find a bug in my code. Not sure why it doesn’t compile? Please help!

https://www.codecademy.com/courses/learn-javascript-control-flow/lessons/control-flow/exercises/else-if?action=resume_content_item&course_redirect=introduction-to-javascript

let moonPhase = ‘full’;

if (moonPhase == ‘full’)
{
console.log(“Howl!”);
}

else if (moonPhase == ‘mostly new’)
{
console.log(“Back on two feet”);
}

else if (moonPhase == ‘mostly full’)
{
console.log(“Arms and legs are getting hairier”);
}

else
{
console.log(“Invalid moon phase”);

}


#2

Hi @btalmage14,

It would be best if you can provide the link (url) towards the lesson and what did the error show when you submit your answer?


#3

Hi @btalmage14,

Thanks for adding the lesson url. Tested your code, it is technically working. But try to follow the lesson’s instruction, look at the hint, follow the order of the conditions according to the lesson, copied from the hint:

if (moonPhase === 'full') {
  ......//your code
} else if (moonPhase === 'mostly full') {
  ..... //your code
} else if (moonPhase === 'mostly new') {
  ...... //your code
} else {
  ....... //your code
}

And just for the sake of passing the lesson, follow their recommendation of using === instead of == (for now when you’re still learning the concepts), there is a significant difference in using === vs == for JavaScript, the usage is not significant in this lesson but for more information you can read here:

Try change what I mentioned above, and hopefully it will let you pass the lesson. Come back if you still facing problem, with the updated codes. Cheers :slight_smile:


#4

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