JavaScript: Control Flow 7/11 else if Statements


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

let moonPhase = ‘full’;

if (moonPhase == ‘full’)

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

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

console.log(“Invalid moon phase”);



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?


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:


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