Created
September 3, 2014 03:13
-
-
Save manderly/d7afc558c553d298c7df to your computer and use it in GitHub Desktop.
Fizz Buzz Chocolate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.