jeudi 5 février 2015

Fizzbuzz game with for loop

I'm trying to do a function that'll print Fizz, Buzz or Fizzbuzz depending on the number can be divided by 3, 5 or both. (this is what I mean: http://ift.tt/YjQuKK)


This is how far I got before I got stuck.



var fizzbuzz = function(start,stop) {
for (var x=1;x <= stop; x++)
var string =',';
if (x%3 == 0) {
string += 'Fizz';
}
if (x%5 == 0){
string += 'Buzz';
}
if (x%5 && x%3){
string += 'Fizzbuzz';
}
return string;
};


I'm getting the answer "," and I'm not sure why.


Aucun commentaire:

Enregistrer un commentaire