...And the good! Help


#1

This code looks like it would work, but I get the error:

Oops, try again. It looks like you printed out the wrong number of items.

Can anyone spot the issue?

for (i = 1; i < 21; i++);

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

else if (i % 5 === 0)
{console.log("Buzz");}

else if (i === 3 && i === 5)
{console.log("FizzBuzz");}

else
{console.log(i);}

#2

ur order is wrong. try

 if (i === 3 && i === 5)
{console.log("FizzBuzz");}

else if (i % 5 === 0)
{console.log("Buzz");}

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

else {console.log(i);}

#3

I've updated the code to individual If/Else statements. Is there anything anyone can spot?

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

#4

I get the same error no matter in what order I put the code! :confused:


#5

Try this one!

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


#6

Your for statement syntax is wrong. You ended it with ; immediately, that's why it does nothing.


#7

Oh, well I'm an idiot. Thanks.


#8

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