Introduction to Objects 1 ....and the good. JavaScript 3/5


#1

I cant think of a reason why this gives the error: SyntaxError: Unexpected token else

for(var i = 1; i < 21; i++){
if(i % 3 === 0){
console.log("Fizz");
}else if(i % 5 === 0){
console.log("Buzz");
}else if(i % 3 === 0 && i % 5 === 0)
console.log("FizzBuzz");
}else{
console.log(i);
}
}

can anyone help me?


#2

The unexpected else,

} else if(i % 3 === 0 && i % 5 === 0)  // missing { brace
console.log("FizzBuzz");
} else {                // is here because of missing brace above

#4

Unexpected end of input usually means there is a missing closing brace on the function body. Add one more brace at the end.

You will still have problem, though. The order of your conditional branches will not output FizzBuzz since the 3 and 5 cases are examined before it. That branch should be first.