Skip to content

Instantly share code, notes, and snippets.

@gbhasha
Last active November 8, 2018 04:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbhasha/351f0329f182d4580a5ed2ba7e0c6a5c to your computer and use it in GitHub Desktop.
Save gbhasha/351f0329f182d4580a5ed2ba7e0c6a5c to your computer and use it in GitHub Desktop.
Write a program that prints the numbers from 1 to 100. But for multiples of three print ‘Fizz’ instead of the number and for the multiples of five print ‘Buzz’. For numbers which are multiples of both three and five print ‘FizzBuzz’.
/*
Write a program that prints the numbers from 1 to 100. But for multiples of three print ‘Fizz’ instead of the number and for the multiples of five print ‘Buzz’. For numbers which are multiples of both three and five print ‘FizzBuzz’.
*/
(function fizzBuzz() {
console.clear();
const isMutlipleOfThree = (i) => (i % 3 === 0 )
const isMutlipleOfFive = (i) => (i % 5 === 0)
const isMutlipleOfThreeAndFive = (i) => isMutlipleOfThree(i) && isMutlipleOfFive(i)
for(let i=1; i<=100; i++) {
if(isMutlipleOfThreeAndFive(i)) {
console.log('FizzBuzz')
} else if(isMutlipleOfThree(i)) {
console.log('Fizz')
} else if(isMutlipleOfFive(i)) {
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