Can anyone help with this code...And the good!?


#1


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

Can anyone see what is going on with my code? I keep getting the error message: "Oops, try again. It looks like you printed out the wrong number of items."

I'm not sure what I am missing. I did the code in the order that they asked. I even copy and pasted other's corrected code, and the window keeps giving me the same error message. :confused:

var fizzBuzz = function() {
  for (var i = 1; i <= 20; i++) {
    if ( (i % 3 === 0) && (i % 5 === 0) ) {
        console.log("FizzBuzz");
    } else if ((i % 3 === 0) && (i % 5 !== 0)) {
      console.log("Fizz");
    } else if ((i % 5 === 0) && (i % 3 !== 0)) {
      console.log("Buzz");
    } else {
    console.log(i);
    }
  }
};


#2

Both moot since the first condition (the if above) pairs them up.


#3

I tried to submit the code without that condition, but I see what you're saying. I'll remove that part. :slight_smile: thanks.


#4

New code:

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

Still doesn't pass the test. Is there something else I am not seeing?


#5

Does not need double parentheses.

Leave the code out in the open, not inside a function. The SCT is not looking for a function, only direct output.


#6

OMG I can't believe that was what I was missing. Having the code in a function. It works now. Thanks for the pro-tips. :slight_smile:


#7

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