3/33 Why is this wrong?


#1

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

Why is my code not passing? I get the error 'unexpected token Else'. Can't find the problem with Else though.


#2

Hm, it worked now. Didn't change anything, maybe a bug in the system that caused it to not register as correct until I refreshed it.


#3

Ok, let's begin with the for loop code. On your if statement, after modulus (%), the operator should be !== . This operator is equivalent to 'not equal value or not equal type'. Same thing goes to 'i % 5'. Your console.log() should be the for loop's name.

console.log(i);

After closing your if statement, let's create an else if statement. Else if is the same as if - just with a different name. Your statement should look like this:

(forLoopName modulus 3 equal value 0 and forLoopName equal value 0) {
// your code goes here
}

So:

else if (i % 3 === 0 && i === 0) {
  // your code goes here
}

Your else if code should console.log(); 'FizzBuzz'.

Now you create the else statement. In your else statement you are going to write another if statement which says:

if (forLoopName % 3 === 0) {
 ...
}

The statement should console.log(); the word Fizz.

And finally the last step! Create another else if statement.

else if (forLoopName % 3 === 0) {
  ...
}

Your code should print the word 'Buzz'.