Help with if/else statments

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/en/courses/learn-javascript/lessons/control-flow/exercises/comparison-operators-ii

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
The prgram has some issue with the else statment but I am doing what it said…

```

var moonPhase = ‘full’;

if (moonPhase === ‘full’);
{
console.log(“howl”);
} else {

console.log(‘i swear i am not a werewolf’);
}

<do not remove the three backticks above>

Here’s the if / else statement structure


if (condition) {
  // do something
} else {
  // do something else
}

Something in your code’s not quite right

1 Like

var moonPhase = ‘full’;

if (moonPhase === ‘full’); {
console.log(‘howl’);
} else {
console.log(‘i am not a werewolf’);
}

I tried this and still getting an error for the ‘else’ statement. It says syntax error , unexpected token “else”

Check my example once more, but don’t focus on the else line, that’s not where the problem is…

1 Like

So you can have a ‘;’ on the //do something lines but not before the first curly bracket??

I removed the first semi colon and it worked. Thanks for the hasty response.

1 Like

That’s right.

By putting the semicolon after the if line, you told the program to move on to something else straight away, which is why you got the else error. The program basically found a random else hanging around without an if. It didn’t process the rest of the if/else statement because of that semicolon.

1 Like

Got it- thanks again!

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