3. ...And the good! - Syntax Error


#1

Having a syntax error that I cannot seem to locate. The error says SyntaxError: Syntax error so I'm not sure where I am overlooking something at.

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

#2

Why not put if(cou % 3 === 0) {
console.log("fizz");
}

Why bother checking if its divisible by 5. When

This should be the first thing checked. big hint there

Also remove the semi-colons after the brace before each new else-if statements so here :

and then the other ones also

Although your code does work fine after removing the semi-colons, its quite complex to look at and understand when there is a much clearer, easy to read solution. (just my thoughts tho, whatever works for you :))


#3

Thank you for the advice. I can understand the reasoning behind keeping easy to read, since as evidenced here, I may not be the only one looking at it. I will work on that.

As far as the semicolons go, is it just functions, loops, and if style statements that don't need them? Or what is the rule for the semicolon as a line break and where it is needed in Javascript vs not?