Last active
August 4, 2019 10:51
-
-
Save yasaryousuf/cf3ed4dc85949b264429b27123e53229 to your computer and use it in GitHub Desktop.
This file contains 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
// Print out all the numbers from 1 to 100. But for every number divisible by 3 print replace it with the | |
// word “Fizz,” for any number divisible by 5 replace it with the word “Buzz” and for a number divisible | |
// by both 3 and 5 replace it with the word “FizzBuzz.” | |
// So your program should output: | |
// 1 | |
// 2 | |
// Fizz | |
// 4 | |
// Buzz | |
// Fizz | |
// 7 | |
// . | |
// . | |
// . | |
const fizzBuzz = i => { | |
if(i % 3 === 0 && i % 5 !== 0){ | |
return 'Fizz'; | |
} else if(i % 5 === 0 && i % 3 !== 0){ | |
return 'Buzz'; | |
} else if(i % 3 === 0 && i % 5 === 0){ | |
return 'FizzBuzz'; | |
} else { | |
return i; | |
} | |
} | |
for(let i = 1; i <= 100; i++){ | |
console.log(fizzBuzz(i)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment