FizzBuzz help


#1

Im doing what it says and it still saying that Im printing out the wrong number of items.. pls help.

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

}


#2

You need another else if statement
{
else if (i % 3 === 0) {
console.log("Fizz");
}


#3

thanks i found what i was doing wrong the whole time. Instead of starting the loop at 1, i was setting it to start at 0. thanks though lol


#4

You can try like this too:

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

#5

thanks for the help :smiley: