1/33 SyntaxError: Unexpected token {


#1

for(var i=0 ; i<=20 ;i++){
console.log(i);
if(i % 3 == 0){
console.log("Bizz");
}else if((i % 5 == 0){
console.log("Fizz");
}else if(i % 3 == 0 && i % 5 == 0){
console.log("FizzBuzz");
}else{
console.log(i);
}
}
What i am doing wrong here.


#2

Remove one of the opening brackets ( on this line:


#3

@julietaatanasova is correct, but you also have a couple other small issues... see comments I added in your code

for(var i=0; i<=20; i++){
console.log(i); //You already log i in your else, don't do it here too
if(i % 3 == 0){
console.log("Bizz");
} else if ((i % 5 == 0){ //one too many brackets, should be (i % 5 == 0)
console.log("Fizz");
} else if (i % 3 == 0 && i % 5 == 0){ //place at front (read more below)
console.log("FizzBuzz");
} else {
console.log(i);
}
};

for your last else if, you want to place it at the top of your If statement. Reason being is that the moment your for loop matches one of your if's, it disregards the rest of the code. So, when the for loop hits 15, it right now will display "fizz" and then move on to 16, when in reality it should be "fizzbuzz". Simply changing the order of your if statement will remedy this.

Alternatively, you could also choose to account for this by adding an AND into your fizz and buzz modulo's. For example it could be like the following:

if(i % 3 == 0 && i % 5 !== 0){
console.log("Bizz");
}

Personally I feel the first solution is better as it is less code to write, but there are alternative ways of getting this to work.

Hope that helps.