Introduction to Objects I- Add the Good


The error message is: SyntaxError: Unexpected token else

I'm not sure what's wrong. Any advice?

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


else can't have a condition statement (which is the things in the bracket).
It's just simply else.

I really suggest you reread the instructions again as else shouldn't be used for "Buzz" but rather the last instruction:

Otherwise, just print out the number.

Use another else if for "Buzz".

Your "Fizz" condition seems to be also messing up your "Buzz" condition as it states that either can be true (definition of the OR operator) but the instructions says only numbers that are divisible by 3 should print "Fizz". And numbers that are divisible by 5 should print "Buzz".

Another thing is to check your syntax. You got unnecessary semicolons at some places (which may cause Unexpected Token errors) and a random var.

Lastly, be sure to put your && statement before anything else. This is to check if the number is divisible by 3 and 5. If it's not, then move on to the individual numbers. Or else the function will skip or never reach the && statement.


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