FizzBuzz code not working


#1


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

I don't understand why this code is not working, I just know that it returns nothing. Can someone please explain it to me?


var counter = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20];

var FizzBuzz;
var repeat = function() {
    for(x = 0; x < counter.length; x++) {
          if ( counter[x] % 3 == !0 && counter[x] % 5 == !0) {
            FizzBuzz = counter[x];
        } else if ( counter[x] % 3 == 0 && counter[x] % 5 == 0) {
            FizzBuzz = "FizzBuzz";
        } else if ( counter[x] % 3 == 0 && counter[x] % 5 == !0 ){
            FizzBuzz = "Fizz";
        } else if ( counter[x] % 5 == 0 && counter[x] % 3 == !0 ) {
            FizzBuzz = "Buzz";
        };
    };
    return FizzBuzz;
};


#2

Hi,

You have to include the return keyword in each of your if else statements. So where you have written Fizzbuzz= "example"; you need to replace it with return "example";. This will then return the string with text to the output. Also it may be worth having another look at how you have done the and arguments in the if else's. They currently all have an && logic argument and only the fizzbuzz actually needs it as it is divisible by 3 AND 5. If you want more code I can paste but will take the fun out!


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

simplified my code and made it work so OORAH. Thanks for the help.