Created
December 16, 2021 20:21
-
-
Save luiznasciment0/97273711afd6c679ebd306abfdec7bef to your computer and use it in GitHub Desktop.
how I usually solve fiz buzz hacker rank challenge
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
/* | |
* Complete the 'fizzBuzz' function below. | |
* | |
* The function accepts INTEGER n as parameter. | |
*/ | |
function fizzBuzz(n) { | |
for (let i = 1; i <= n; i++) { | |
// const isMultipleOfThreeAndFive = i % 3 === 0 && i % 5 === 0; | |
const isMultipleOfThreeOnly = i % 3 === 0 && i % 5 !== 0; | |
const isMultipleOfFiveOnly = i % 5 === 0 && i % 3 !== 0; | |
const isNotAMultipleOfThreeOrFive = i % 3 !== 0 && i % 5 !== 0; | |
if (isNotAMultipleOfThreeOrFive) { | |
console.log(i); | |
} else if (isMultipleOfFiveOnly) { | |
console.log('Buzz'); | |
} else if (isMultipleOfThreeOnly) { | |
console.log('Fizz'); | |
} else { | |
console.log('FizzBuzz'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
my implementation