3. Tells me problem with syntax is )


#1

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


#2

Use var i in your for loop:


#3

in addition to what @julietaatanasova has said you need to use semicolons instead of commas to separate the elements of the for loop

for(var i = 1; i <= 20; i++) {

#4

And, if it still doesn't work, use i < 21 instead of i<= 20. It should run the same, but with computer language you never know.


#5

Thank you for the help the only problem is now it isn't returning FizzBuzz, but thank you :smile:


#6

you have to put this block

else if(i % 3 == 0 && i % 5 == 0) {

before all the other blocks

and use this === comparison operator not ==


#7

This code is unreachable:

because if (i % 3 == 0) the program will print "Fizz", and if (i % 5 == 0) - "Buzz". There is no chance to reach the code where (i % 3 == 0 && i % 5 == 0) is true.

Try this:

} else if(i % (3 * 5) == 0) {    
    console.log("FizzBuzz");
}

#8

Why are we declaring
if(i % 3 === 0 && i % 5 === 0){
console.log("FizzBuzz");
}
This code before all other blocks??? Please help...Thank you


#9

you have to put this condition (i%3 === 0 && i%5 === 0 ) as the first one to be checked first


#10

since I am using pro and my advisor suggested me the following which really works. Try in the following way

"""So you're code is reeeeally close!

The problem is that in the conditionals, if a number is divisible by 3, then you print "Fizz". However, if it is divisible by both 3 AND 5, then you print "FizzBuzz"! So first, you would want the program to check if it is divisible by 3 and 5, and then go on to check if it is just divisible by 3 if your first condition fails.
Otherwise, it will never get to that last conditional you have, because it will have already checked if the number is divisible by 3, and then divisible by 5, and it will never have checked if it was divisible by both. Does that make sense?!"""


#11

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

else{console.log(i);}

};