Created
May 2, 2022 01:22
-
-
Save nitrotap/f51cd4a02f76efb47b6aaa5f8d4b1f1f to your computer and use it in GitHub Desktop.
Fizz Buzz solution
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
// Write code to loop through the array of numbers | |
// At each iteration, if a number is evenly divisible by 3 print "Fizz" | |
// If a number is evenly divisible by 5 print "Buzz" | |
// If a number is evenly divisible by both 3 AND 5, print "Fizz Buzz" | |
// If a number is not divisible by 3 or 5, print the number | |
const fizzBuzz = function(arr) { | |
for (let i in arr) { | |
let currentNumber = arr[i]; | |
if (currentNumber % 15 === 0) { | |
console.log('Fizz Buzz'); | |
} else if (currentNumber % 3 === 0) { | |
console.log('Fizz'); | |
} else if (currentNumber % 5 === 0) { | |
console.log('Buzz'); | |
} else { | |
console.log(currentNumber); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment