Error with if/else statement


<Below this line, add a link to the EXACT exercise that you are stuck at.>

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
I’ve tried to do this exercise using an if/else statement, but it doesn’t like my else after the first block. When I remove the else and semicolon it will run (incorrectly), and I will be able to move on. Is there something wrong with my code or is it a problem on codecademy’s end?

This is the error I'm getting from the compiler:

} else; {
SyntaxError: Unexpected token else
at createScript (vm.js:53:10)
at Object.runInThisContext (vm.js:95:10)
at Module._compile (module.js:543:28)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)

``` This was my code:

var moonPhase = ‘full’;
if(moonPhase === ‘full’); {
} else; {
console.log(‘I swear I am not a werewolf…’);


Just remove both of the semicolons below and it should work.

1 Like

Thanks! Is there a reason why I would want to remove these semicolons? I thought they were used to end lines of code

The semicolons indicate end of statements, and are used to separate one statement from another. The if/else syntax, along with for, while etc… does not contain semicolons. Here is a useful guide on semicolons for JS, take a look. I’m not really good at explaining things :frowning:

Semicolons in JavaScript

Hope it helps!

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