Skip to content

Instantly share code, notes, and snippets.

@robertpateii
Forked from anonymous/fizzbuzz.js
Last active December 17, 2015 04:18
Show Gist options
  • Select an option

  • Save robertpateii/5549133 to your computer and use it in GitHub Desktop.

Select an option

Save robertpateii/5549133 to your computer and use it in GitHub Desktop.
Had to write my own version before before I ask other people to do the same. http://c2.com/cgi/wiki?FizzBuzzTest
var fizzBuzz = function fizzBuzz () {
"use strict";
var fizzArray = [];
var fizzNumCheck = function fizzNumCheck (num) {
var numString = "";
if (num % 3 === 0) {
numString += "Fizz";
}
if (num % 5 === 0) {
numString += "Buzz";
}
if (numString.length === 0) {
numString += num.toString();
}
return numString;
};
for (var i = 0; i < 100; i++) {
fizzArray[i] = fizzNumCheck(i+1);
}
console.log(fizzArray);
};
fizzBuzz();
@robertpateii
Copy link
Copy Markdown
Author

I accidentally created it anonymously at first, so I forked it. Then I made some changes based on reading other implementations. Using status variables for each test would have complicated things if more tests were added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment