And the good.. or not that good


#1

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

What is wrong here?


#2

what happens when you run it


#3

says try again! You printed Fizz when you should have printed FizzBuzz.

:confused:


#4

okay..... try putting your last "else-if"condition as the first. remember to change it to an 'if' condition.


#5

this worked for me
for (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

Why does the FizzBuzz conditional need to come before all the others for it to work correctly?


#7

Theres is more than one way to solve it. That is just the easiest way to do it.
Another way is by nesting the if statement, but you have to do it right. Or else the code will break.


#8

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