Last active
November 8, 2018 04:54
-
-
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’.
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
/* | |
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