Else if statements


#1
let moonPhase = "mostly new";

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");}

Hi.

Everytime I execute this code I get the expected answers and no error code but the application tells me that it is wrong. What is the problem here?


#2

the way you placed the curly brackets, it should be:

if(moonPhase === "full"){ 
    console.log("Howl!");
}

or something. You need at least the { on the same line as the if, else if or else keyword

next time, please include an exercise url also so we can quickly navigate to the exercise and test the issue, also do this if you need further help in this topic


#3

Why do you enforce this way of coding if it gives no errors?


#4

I don’ enforce anything, i am merely helping out on the forum.

There usually two ways you write curly brackets:

if (condition){
    // code
}

or:

if (condition)
{
    // condition
}

what you did is very uncommon practice, and will earn you a frown by more experienced programmers

Not sure why codecademy is enforcing the first way, but enforcing some good practices is surely a good idea.


#5

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