Else if statements

let moonPhase = "mostly new";

if(moonPhase === "full")
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");}


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?

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

if(moonPhase === "full"){ 

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


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

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

There usually two ways you write curly brackets:

if (condition){
    // code


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.


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