Else if Statements


#1

I'm having trouble with elseif Statements. Can someone help me figure out what I'm missing?


Excercise 5 section 5

I'm trying to get the code to say the following.
If the moon is 'mostly full', log 'Arms and legs are getting hairier' If the moon is 'mostly new', log 'Back on two feet'.

If someone enters in an invalid moon phase, make sure to the final else to log 'Invalid moon phase'.


 

1 var moonPhase = full;
2 if(moonPhase==='mostly full') {
3  console.log('Arms and legs are getting hairier');}
4 else if (moonPhase==='mostly new') {
5  console.log('Back on two feet');
6 } else console.log('Invalid moon phase');


#2

You define moonPhase as an unknown type of variable. Add quotes around it, and your if statements will begin to accept it. You ask for strings in the if statements, but define something else in moonPhase.

New Code:

1 var moonPhase = "full";
2 if(moonPhase==='mostly full') {
3  console.log('Arms and legs are getting hairier');}
4 else if (moonPhase==='mostly new') {
5  console.log('Back on two feet');
6 } else console.log('Invalid moon phase');

#3

what are you one you mess


#4

When defining moonPhase, it was defined as something other than a string,
so it's value is reflected accordingly. The if statements ask for specific
Strings, which are never received because the value isn't of a String type.
So the else condition always excecutes.


#5

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