3. ...And the good! (can you help me !)


#1

for (var i=1; i<=20 ;i++)
{

if(i % 3 && 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);
}
}

Oops, try again. You printed FizzBuzz when you should have printed Buzz


#2

if you use and (&&) or or (||) operator, comparison should be done at both sides of the operator:

if (x == 5 && y == 5){
  console.log("success")
}

you only did comparison at one side of the and operator


#3

Hi @ragu86
Please try to format your code correctly next time you post.

Instead of just i%3 && i%5==0 you need to put the ==0 twice. So your if would look like this:

if(i % 3 && i % 5 == 0){

Hope this helps.

(Answered by @stetim94 here.)


#4

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