Skip to content

Instantly share code, notes, and snippets.

@manderly
Created September 3, 2014 03:13
Show Gist options
  • Save manderly/d7afc558c553d298c7df to your computer and use it in GitHub Desktop.
Save manderly/d7afc558c553d298c7df to your computer and use it in GitHub Desktop.
Fizz Buzz Chocolate
var str = "";
var params = {
3:"fizz",
5:"buzz",
8:"chocolate"
};
for (var i = 0; i < 100; i ++ ) {
str = i + " ";
for (var key in params) {
if (params.hasOwnProperty(key) && i % key === 0) { //hasOwnProperty(key) restricts this check to properties I set manually
str += params[key];
}
}
console.log(str);
}
@manderly
Copy link
Author

manderly commented Sep 3, 2014

Inspired by one of Ivan Stork's in-class challenges in the Full Stack JavaScript Dev Accelerator at Code Fellows, Seattle. This version of Fizz Buzz uses object parameters in place of variables or hard-coded numbers.

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