# ...and the good! Sintax question

#1

Hi Guys! I've solved the "and the good" but i have one question.
When i tried to create my code its was like this:

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

else {
console.log(i);
}

}``````

But it didn't work, after running a few tests i tried to start with the condition with the two possibilities and then.....it worked!
Can anyone explain me why? Why this only works if we verify that condition first?

Thanks
(Sorry for my bad English)

``````for (i = 1; i < 21; i++) {
if (i % 5 === 0 && i % 3 === 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

What were the instruction ?

#3

Sorry i don't understand what are you asking..

#4

So here's my code; I'll try to explain this the best I can.

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

Based on your second image, I think you forgot to put the semi-colon ( ; ) at the very end. Also, it should be

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

Hope it helps!

#5

well but the 2nd image it's whe one that worked xD

#6

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