...And the good!: What's wrong with this (working) code?


#1


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


My codde works perfectly according to rules - it logs the Fizz and Buzz or number. The system however complains

"Oops, try again. You printed Buzz when you should have printed 1"

which is not true - I indeed log a 1 instead of any string for the latest case;

for (var i = 20; i > 0; i--){
    var ans = "";
    if (i % 3 === 0) ans += "Fizz";
    if (i % 5 === 0) ans += "Buzz";
    console.log(ans ? ans : i);
}


#2

Print out the numbers from 1 - 20.

not from 20 - 1


#3

Of course! Thank you. Funny mistake though, cannot imagine why I decided to count down.


#4

you're very welcome :slight_smile:


#5

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