Last active
May 29, 2020 15:47
-
-
Save mjmeilahn/4acb925209be5a7bd2d301c65e3370c7 to your computer and use it in GitHub Desktop.
JS: Fizzbuzz Function
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
// DESCRIPTION | |
// Counting from 0 to 100, print out each number in the console. | |
// RULES | |
// 1. If the number is a multiple of 3, print "fizz" instead of the number. | |
// 2. If the number is a multiple of 5, print "buzz" instead of the number. | |
// 3. If the number is a multiple of both 3 and 5, print "fizzbuzz" in place of the number. | |
// 4. Otherwise just print the number itself. | |
// 5. Each entry should be printed on a new line. | |
const fizzbuzz = () => { | |
for (let i = 0; i <= 100; i++) { | |
if (i % 5 === 0 && i % 3 === 0) { | |
console.log('fizzbuzz'); | |
} | |
else if (i % 3 === 0) { | |
console.log('fizz'); | |
} | |
else if (i % 5 === 0) { | |
console.log('buzz'); | |
} | |
else { | |
console.log(i); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment