My code works in the chrome console and atom editor but not codecademy? For Unit 7 Lesson 3


#1

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

The task:
Print out the numbers from 1 - 20.
The rules:
For numbers divisible by 3, print out "Fizz".
For numbers divisible by 5, print out "Buzz".
For numbers divisible by both 3 and 5, print out "FizzBuzz" in the console.
Otherwise, just print out the number.

myCode:

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

ErrorMessage:
Oops, try again. It looks like you printed out the wrong number of items.

Technically its spot on it does what it supposed to do so I'm assuming I'm not getting the checkmark from codecademy because I didn't use some type of convoluted nesting like the lesson requested.


#2

for(var i = 0; i < 21; i += 1) // count from 1 not 0

#3

lol its always something obvious... thanks


#4

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