Skip to content

Instantly share code, notes, and snippets.

@classmember
Created September 16, 2017 16:28
Show Gist options
  • Save classmember/454f131cf31523676ab0e5b520a02c8e to your computer and use it in GitHub Desktop.
Save classmember/454f131cf31523676ab0e5b520a02c8e to your computer and use it in GitHub Desktop.
/**
* 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