Help with if/else statments


The prgram has some issue with the else statment but I am doing what it said...

var moonPhase = 'full';

if (moonPhase === 'full');
} else {
  console.log('i swear i am not a werewolf');


Here's the if / else statement structure

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

Something in your code's not quite right


var moonPhase = 'full';

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


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.


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.


Got it- thanks again!


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