3... And the good!


#1

Why does it keep saying "SyntaxError: Unexpected token &&".. Can you please HELP ME!??
Here is the code:
for (i=1; i<=20; i++) {
if (i % 3 === 0) && (i % 5 === 0) {
console.log("FizzBuzz");
}
else if (i % 5 === 0) {
console.log("Buzz");
}
else if (i % 3 === 0) {
console.log("Fizz");
}
else {
console.log(i);
}
}


#2

Remove the parentheses closest to the && symbol. They are breaking your condition into separate pieces.


#3

I have tried that but it didn't work!


#4

Can we see your code with the most recent alterations?


#6

Your "i<=20" should be using the length of the array you declared initially. For example, i < array.length. Which will still equal to 20 if your array contains 20 'things' in it.

The if condition should always be within one bracket and only one. Here you have written two brackets. The previous quote I mentioned should be using arrays. Your if condition should look something like this:

if (array[i] % 3 === 0 && array[i] % 5 === 0)

Other than that, your code looks fine. You should just need to replace the varaible of 'i' to the array instead.

Hope this helps you.


#7

Hi. indent your if and else if statements. Mine worked and looks exactly like yours except everything falls under the very first statement (for loop) and also remove the brackets in the if ( if (i % 3 == 0 && i%5==0) statement so its just one statement

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);

}

}


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.