Skip to content

Instantly share code, notes, and snippets.

@jialinhuang00
Last active October 2, 2017 09:38
Show Gist options
  • Save jialinhuang00/708c311e99a96bb11063a12938358279 to your computer and use it in GitHub Desktop.
Save jialinhuang00/708c311e99a96bb11063a12938358279 to your computer and use it in GitHub Desktop.
/*-----------------------------------------------------------------------------
1.check the multiple
2.the fifteen's case must be first.
the reference is from UdemyCourse: LearningAlgorithmsInJavascriptFromScratch
-----------------------------------------------------------------------------*/
// 15X ->> 'FizzBuzz'
// 5X ->> 'buzz'
// 3X ->> 'fizz'
function fizbuz(n) {
var i;
for (i = 0; i < n; i++) {
if (i % 15 === 0) {
console.log("FizzBuzz");
} else if (i % 3 === 0) {
console.log("fizz");
} else if (i % 5 === 0) {
console.log("buzz");
} else console.log(i);
}
}
fizbuz(49);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment