/* ------------------------------------------------------------------------------------------------
CHALLENGE 7
Write a function named fizzbuzz that takes in an array of numbers.
Iterate over the array using forEach to determine the output based on several rules:
- If a number is divisible by 3, add the word "Fizz" to the output array.
- If the number is divisible by 5, add the word "Buzz" to the output array.
- If the number is divisible by both 3 and 5, add the phrase "Fizz Buzz" to the output array.
- Otherwise, add the number to the output array.
Return the resulting output array.
------------------------------------------------------------------------------------------------ */
const fizzbuzz = (arr) => {
let output = [];
arr.forEach(function(e){
if (e%3==0 && e%5==0)
output.push('Fizz Buzz');
else if (e%3==0)
output.push('Fizz');
else if (e%5==0)
output.push('Buzz');
else
output.push(e);
});
return output;
};
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.