And the good!


#1


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


"you printed fizz when you should have printed FizzBuzz."I'm stuck here. Need help.Thanks.


Replace this line with your code.


#2

for(var 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);
}

};


#3

The error that you are getting is in reference to the order that you put your conditionals. When an if statement sees that a condition is met, it will execute that condition and then end the if statement. Because your first conditional is to check if it is divisible by 3, it executes that section and never gets to the part where it checks if it is divisible by both 3 and 5. So the only change that you have to do is to change the order of your conditional statements, like so:

for (var i = 1; i <= 20; 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);
    }
};

I hope that helps :smile:


#4

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