3/5 ...And the good!


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

} else {
console.log(i);
}

};

It says that i have an 'Syntax Error: Unexpected token ===' and I can't seem to find it, please help!!


#2

This is your code corrected. take a look at it and see the difference

Edit:

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

#3

Nope, it says that it printed to wrong number of items...


#4

made an edit to the original post i made


#5

thank you, but can you possibly explain how you were able to fix it for future issues?


#6

in your code you were writing

 i%===3
//but it should rather be

i%3 ===0// you want check if the current number is divisible by 3

logicwise the only part i changed is

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

for this

     //if the number is divisible by three
    if (i % 3===0) {
         //check if the that same number is divisible by 5
        // if it is then print "FizzBuzz"
        if(i%5 ===0){console.log("FizzBuzz");}
        //if the number is not divisible by 5 then print fizz
        else{console.log("Fizz");} 
    }

#7

Well, thanks a lot, this helped me understand a lot!!


#8

Why is this not working?
Err: SyntaxError: Unexpected end of input

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


#9

add a } at the end of your code


#10

Thank you, that worked:)