...And the good!


#1


https://www.codecademy.com/courses/spencer-sandbox/0/3?curriculum_id=506324b3a7dffd00020bf661#


Hey guys. It keeps printing Fizz when it should print FizzBuzz. Can't figure out what is wrong? Thanks! :sunglasses:


for (var i=1; i<21; 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

Figured it out guys :slight_smile:

Had to put the "FIzzBuzz" statement in the top.. Otherwise it will only check if it matches one of the first 2, and if it does it will execute that one it matches first :sunglasses:

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

}


#3

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