# Need help with 3:/ ...and the good

#1

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

#2

you can also do it this way

function fizzBuzz() {

``````for (i = 1; i <= 500; i++){
if (i%3 === 0 && i%8 === 0){
console.log("FizzBuzz");
}
else if(i%3 === 0){
console.log("Buzz");``````

}

else if (i%8 === 0){
console.log("Fizz");
}
else {
console.log(i);
}
}
}
fizzBuzz();

#3

You need to put this condition as the first condition to be checked

because if you take the case of the number "15", it is both a multiple of 3 and 5 => it must be displayed as "FizzBuzz"
but from your code it'll be displayed as "FIzz", as the code just checks whether its a multiple of 3.
So, just prioritize the conditions.

Hope this helps.

#4
``````// I set i = 1 because otherwise it would start with 0
//and display FizzBuzz instead of starting on 1.
//i < 21 works as well``````

for (i = 1; i <= 20; i++) {
/////if ((i % 3 == 0) && (i % 5 == 0)) {
/////////console.log("FizzBuzz")
//This block first because if one of the other 2 if/else
//got to 15 before this one they would display just fizz or buzz
//and skip the FizzBuzz Portion
}
else if (i % 3 == 0) {
console.log("Fizz")
}
else if ( i % 5 == 0) {
console.log("Buzz")
} else {
console.log(i)
}
}