I can't find why it prints out Fizz when it should print 1 please help!


#1



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

When I run the code it says Oops, try again. You printed Fizz when you should have printed 1. Please help and thanks in advance!

for(i = 0; i < 20; 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

Hi,

The instruction says "Print out the numbers from 1 - 20."
Your loop goes through the numbers 0 to 19.


#3

It's the first line. Change i=0 to i = 1 and 20 to 21 and it should work. Hope this helps Zebrthe!


#4

Thanks guys! This solves why it prints Fizz when it should have printed 1 but now I get the error message "Oops, try again. You printed Fizz when you should have printed FizzBuzz". Does anyone know why?


#5

the short answer is you put in the most specific condition:

if(i % 3 === 0 && i % 5 === 0) {
console.log("FizzBuzz")

first.

the long and thorough answer is in this thread:


#6

Thank you! This works great!