Stuck on 3


#1


https://www.codecademy.com/en/courses/spencer-sandbox/0/3?curriculum_id=506324b3a7dffd00020bf661#

Oops, try again. It looks like you printed out the wrong number of items. Anyone know what I did wrong?

for (var i = 0; i<21; i++) {
    console.log(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);
}


#2

The first number printed should be 1, and the last should be 20 (Buzz). What is showing up when you run your code?

Edit: (I'm at the post limit for a new user. If someone could reply to alex for me I would appreciate it!)
Your starting point is wrong - the first number should be 1.
Line 2 is the only thing in your for loop right now! It's printing each i until the loop ends.
Once your if statements are in the for loop, you'll still need to make a few changes - right now 15 would be "Fizz" instead of "FizzBuzz"


#3

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Fizz


#4

he's replying to you via edting his comment in case you didn't see it


#5

try this
for(var i = 1; i < 21 ; i++){
if (i % 5 === 0&& i % 3 === 0) {
console.log("FizzBuzz");
}
else if (i % 5 === 0) {
console.log("Buzz");
}
else if (i % 3 === 0) {
console.log("Fizz");
}
else {
console.log(i);
}
};
the order of the if statements matters, the same thing was happening to me until I swithced the order


#6

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