0

working through the tutorial. I wrote a piece of code to return all numbers in range and replace those %3 && 5% or both with a string, but for whatever reason codeacademy returns an error (Oops, try again. It looks like you printed out the wrong number of items).

Here is my code, hopefully you can enlighten me where the problem is:

function fizzBuzz(num){
  var i = 1;

  while(i <= num){

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

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

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

    } else {
      console.log(i);
      i++;
    }
  }
}
console.log(fizzBuzz(20)); 
2
  • 1
    You should give us more hints about the expected output Commented May 15, 2016 at 17:17
  • To answer, we would need to know the exact requirements of the challenge. Commented May 15, 2016 at 17:17

1 Answer 1

2

While I will not comment on the quality of your fizzBuzz function (because it won't be glowing with positive comments...) you are calling console.log(fizzBuzz(20)), which - since there is no return statement in that function - will log undefined to the console, which is one item more than Code Academy expects.

Just call fizzBuzz(20);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.