3...And the Good


#1

Why is this not correct?

for (var i=1; i<=20; 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);
}
};


#2

We never write a semi-colon before an else.

We never write an opening brace before the conditional expression in an if statement.


#3

Syntax error at the 4th line of your code. Placement of the semicolon needs attention. You have written:

Your semicolon should be inside the curly bracket. Like this:
{console.log("FizzBuzz");}

Check the 'else if' as suggested by mtf.

And an extra semicolon at the end of the entire code which is not required. Get rid of the last semicolon.

It is always a good idea to check your syntax thoroughly before asking help. It will help you in the long run. As things might get more complex. Another good practice is writing the code with proper indentation.


#8

I sometimes do not follow indentation and then my code get really messy. :stuck_out_tongue_winking_eye:


#9