Created
June 30, 2016 03:18
-
-
Save mrbobbybryant/77300a3348aa09fdff7499e87deb7c4b to your computer and use it in GitHub Desktop.
My answer to the fizzbuzz coding challenge
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
function divisibleBy3(number) { | |
return number % 3 === 0; | |
} | |
function divisibleBy5(number) { | |
return number % 5 === 0; | |
} | |
function divisibleByBoth(number) { | |
return divisibleBy3(number) && divisibleBy5(number); | |
} | |
function outputFizzBuzz(number) { | |
if (divisibleByBoth(number)) { | |
return 'FizzBuzz'; | |
} | |
if (divisibleBy5(number)) { | |
return 'Buzz'; | |
} | |
if (divisibleBy3(number)) { | |
return 'Fizz'; | |
} | |
return number; | |
} | |
function runFizzBuzz() { | |
var i = 0; | |
while(i < 100) { | |
i++; | |
console.log(outputFizzBuzz(i)); | |
} | |
} | |
runFizzBuzz(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment