Attempting the classic 'FizzBuzz' challenge in JavaScript this time. Managed to complete the basic challenge and now looking to level up. For those new to FizzBuzz, the goal is to print numbers 1..100
but replace multiples of 3
with Fizz
, multiples of 5
with Buzz
, and multiples of both with FizzBuzz
. What I'm aiming for is a function that takes an array as input and returns the modified array. For instance:
function super_fizzbuzz(array){
var super_array = [];
for (var i=0; i<array.length; i++)
{
if (array[i] % 15 == 0)
super_array.push("FizzBuzz");
else if (array[i] % 5 == 0)
super_array.push("Buzz");
else if (array[i] % 3 == 0)
super_array.push("Fizz");
else
super_array.push(array[i]);
}
return super_array;
}
console.log(super_fizzbuzz([3,10,15,19]));
The expected result should be ["Fizz", "Buzz", "FizzBuzz", 19]
, but currently it's returning an empty array. Just worked through this in Ruby successfully, now practicing my JavaScript skills. Any tips would be welcomed!