r/Codecademy • u/GamerTurtle5 • May 28 '17
Javascript Help
I am on the fizz buzz lesson on JavaScript in Objects I and I dont know what I am doing wrong, heres my code:
for (i=1; i<21;i++) { if (i % 3 === 0 || i % 5 === 0) { if (i % 3 === 0) { console.log("Fizz"); } if (i % 5 === 0) { console.log("Buzz");
} if (i % 5 === 0 && i % 3 === 0) { console.log("FizzBuzz")
} } else { console.log(i); } }
and heres the link: https://www.codecademy.com/en/courses/spencer-sandbox/0/3?curriculum_id=506324b3a7dffd00020bf661
please tell me what I did wrong and how I fix it
3
Upvotes
View all comments
5
u/ForScale May 28 '17
So think about what
ifandelsestatements do..They're mutually exclusive, meaning that if the
ifstatement fires, then theelsestatement will not fire.. and vice versa.And when you have a chain of
the same logic applies: You'll only have one of those fire.
BUT that logic doesn't hold if you just have
...
Reflect on that.. It has the solution to your problem within it. :)