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

javascript

#1

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-javascript-control-flow/lessons/control-flow/exercises/else-if?action=lesson_resume&course_redirect=introduction-to-javascript

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`){
  console.log(`Howl!`);
}else if(moonPhase === `mostly full`){
  console.log(`Arms and legs are getting hairer`);
}else if(moonPhase === `mostly new`){
  console.log(`Back on two feet`);
}else{
  console.lof(`Invalid moon phase`)
}


#2

Hi @aaronjoseph2001,

You’re using a backtick ` symbol

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

Example:

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') {
  console.log('Go!');
} else {
  console.log('Caution, unknown!');
}

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

Cheers! :slight_smile:


#3

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


#4

You’re welcome @aaronjoseph2001,

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

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

 //codes
 //....

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

Note:

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

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

:slight_smile:


#5

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


#6

@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:


#7

Need help with code review

Code:
let moonPhase=‘full’;
/if(moonPhase===‘full’)
console.log(‘Howl!’);
else
console.log(‘I swear I am not a werewolf.’);
/
if(moonPhase===‘full’)
console.log(‘Howl!’);
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’);

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?


#8

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