Help with if/else? I don't know what I'm doing wrong


#1

https://www.codecademy.com/courses/learn-javascript/lessons/control-flow/exercises/else-if?action=lesson_resume

I can't tell what I'm doing wrong! It keeps asking if I've logged "Arms and legs are getting hairier" to the console.....
I don't understand if/else statements D:

 var moonPhase = ‘full’;

if (moonPhase === ‘full’) {
	console.log(‘Howwllll!!’);

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

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

else (moonPhase = ‘solar eclipse’);
	console.log(‘Invalid moon phase’);

#2

Hi there,

First. The if - else if syntax is as follows.


if(condition)
{
doSomething;
}
else if (condition)
{
doSometing;
}
else
{
doSomething;
}

Note that the final 'else' does not has a condition to evaluate, since if the above conditions don't match, the else will be executed.

Each statement should have their own '{}'. Also, the semicolon means end of statements, so remove those after your if/else like this one

Additionally, change the ’ for ' or ".


#3

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