Created
September 16, 2017 16:28
-
-
Save classmember/454f131cf31523676ab0e5b520a02c8e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* fizzbuzz in javascript | |
* @return {string} - output of fizzbuzz coding challenge | |
*/ | |
function fizzbuzz() { | |
let output = ''; // initialize return string | |
for (tmp=1; tmp<=100; tmp++) { // iterate from 1 to 100 | |
if ((tmp % 15) === 0) { // if divisible by 3 and 5 | |
output += 'fizzbuzz'; // add 'fizzbuzz' | |
} else if ((tmp % 3) === 0) { // if divisible by just 3 | |
output += 'fizz'; // add 'fizz' | |
} else if ((tmp % 5) === 0) { // if divisible by just 5 | |
output += 'buzz'; // add 'buzz' | |
} else { // else | |
output += tmp; // add value of iterator variable | |
} | |
output += '\n'; // add newline character | |
}; | |
return output; // output return string | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment