Exercise 9/11 – help with code review for if statement



<Below this line, add a link to the EXACT exercise that you are stuck at.>

it says Did you write an else if statement for if the moonPhase is mostly new?
but i write already

let moonPhase = `full`

if(moonPhase === `full`){
}else if(moonPhase === `mostly full`){
  console.log(`Arms and legs are getting hairer`);
}else if(moonPhase === `mostly new`){
  console.log(`Back on two feet`);
  console.lof(`Invalid moon phase`)


Hi @aaronjoseph2001,

You’re using a backtick ` symbol

For string values, you should use single quote ' ' or the double quotes " ".


let stopLight = 'green';  //<== Notice the quotation mark? It's not backtick symbol

if (stopLight === 'red') {  //<== Same goes for the rest
  console.log('Stop');       //<==  
} else if (stopLight === 'yellow') {
  console.log('Slow down');
} else if (stopLight === 'green') {
} else {
  console.log('Caution, unknown!');

Change all the backticks into single quote ' ', your code should work.

Cheers! :slight_smile:


@codexthon Thanks a lot bro
i didn’t think of that


You’re welcome @aaronjoseph2001,

Just for completeness. There’s two semicolons should be added (not a must, but for completeness)

let moonPhase = 'full';  //<== here


  console.log('Invalid moon phase');   //<== here


And I just notice this spelling error in your code, it’s console.log

  console.lof('Invalid moon phase')  //<== spelling



wa your eyes are good man you must teach me how you do it
anyway thanks again


@aaronjoseph2001, just more practice and a curious mind. By helping to figure out why codes don’t work, it certainly improves my debugging skill.

Sometimes, just one spelling difference could throw error and make the code unusable. :joy:

That said, you’re welcome and have fun coding! :grinning:


Need help with code review

let moonPhase=‘full’;
console.log(‘I swear I am not a werewolf.’);
else if(moonPhase===‘mostly full’)
console.log(‘Arms and legs are getting hairier’);
else if(moonPhase===‘mostly new’)
console.log(‘Back on two feet’);
console.log(‘Invalid moon phase’);

This program runs smoothly, but a message “Did you write an else statement that logs ‘Invalid moon phase’?
” is displayed.
Can anyone explain why is this message displayed?


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