It looks like you've printed out the wrong number of objects


#1


3. ...And the good!


I'm getting an error message that says that I've printed out the wrong number of items. The code is not posting anything to the console.


var oneThroughTwenty = function() {
for(var i = 0; i < 20; i++) {
    console.log(i)

if (oneThroughTwenty % 3 === 0) {
    console.log("Fizz")
}
else if (oneThroughTwenty % 5 === 0) {
    console.log("Buzz")
}
else if ((oneThroughTwenty % 3) && (oneThroughTwenty % 5)) {
    console.log("FizzBuzz")
} 
}
};
oneThroughTwenty


#2

If you want to loop through values up to 20, what should your condition check? Will i<20 return those values?

This is not how you call a function to the console.


#3

oh oops, so i = 1; i < 21, i++
then, oneThroughTwenty();


#4

I fixed it turns out there was a whole bunch of stuff wrong with my code


#5

What's wrong in the code below?

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

if (i%3 === 0) {
    if (i%5 === 0) {
    console.log("FizzBuzz");
} 
    else{console.log("Fizz");}
}
else if (i%5 === 0) {
    console.log("Buzz");
}

}

#6

you can't have to if statements so you have to use && to make the condition. So for example
if ((i % 3 === 0) && (i % 5 === 0) {
console.log("FizzBuzz")
}
also if you're using 'else if' that needs to go in the middle and 'else' goes at the end.
by using 'else' to log "Fizz" you're basically telling the computer to print "Fizz" for all numbers that aren't divisible by 3 or 5 when "Fizz" should only be logged when the number is divisible by 3.
and to print everything to the console make sure you put
console.log(i) at the end. but make sure it is still inside the 'for' code!


#7

You're right. Thanks!


#8

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