JavaScript Challenge - FizzBuzz

function fizzbuzz(n) {

// Write your code here

const newArray = ;

for (let i = 1; i <= n; i++) {

if (i % 3 === 0 && i % 5 === 0) {
  newArray.push("FizzBuzz");
} else if (i % 3 === 0) {
  newArray.push("Fizz");
} else if (i % 5 === 0) {
  newArray.push("Buzz");
} else {
  newArray.push(i);
}   

}
return newArray;

}

console.log(fizzbuzz(16));

// Leave this line for testing:
module.exports = fizzbuzz;

function fizzbuzz(n) { // Write your code here const newArray = [ ]; for (let i = 1; i <= n; i++) { if (i % 3 === 0 && i % 5 === 0) { newArray.push("FizzBuzz"); } else if (i % 3 === 0) { newArray.push("Fizz"); } else if (i % 5 === 0) { newArray.push("Buzz"); } else { newArray.push(i); } } return newArray; } console.log(fizzbuzz(16)); // Leave this line for testing: module.exports = fizzbuzz;

Hello here is my code :
function fizzbuzz(n) {
// Write your code here
let i = 1
const arr =
while(i<=n) {
arr.push(i)
i++
}
for(let j = 0; j <= arr.length; j++) {
if(arr[j] % 3 === 0 && arr[j] % 5 === 0) {
arr[j] = ‘FizzBuzz’
} else if(arr[j] % 5 === 0) {
arr[j] = ‘Buzz’
} else if(arr[j] % 3 === 0) {
arr[j] = ‘Fizz’
}
}
return arr

}

console.log(fizzbuzz(16));

// Leave this line for testing:
module.exports = fizzbuzz;

v2 with range and map function

const _ = require('lodash');

function fizzbuzz(n) {
  return _.range(1, n + 1)
  .map(e => !(e%5) && !(e%3) ?
     'FizzBuzz' : !(e%3) ?
       'Fizz' : !(e%5) ?
         'Buzz' : e)
}

// Leave this line for testing:
module.exports = fizzbuzz;

My humble solution.

function fizzbuzz(n) { let arr = [] for(let i = 1; i <= n; i++){ let str = "" if(i % 3 ===0) { str += "Fizz"}; if(i % 5 === 0) { str += "Buzz"}; str ? arr.push(str) : arr.push(i) } return arr } console.log(fizzbuzz(16)); // Leave this line for testing: module.exports = fizzbuzz;

Here is my code:

function fizzbuzz(n) { // An array for keeping track of the numbers and strings. const list = []; // A loop that goes through all the numbers for the parameter n. for (i = 1; i <= n; i++) { // Adds the string to list if it's a multiple of 5 or 3. if (i % 5 === 0 && i % 3 === 0) { list.push("FizzBuzz"); // Adds the string to list if it's a multiple of 5. } else if (i % 5 === 0) { list.push("Buzz"); // Adds the string to list if it's a multiple of 3. } else if (i % 3 === 0) { list.push("Fizz"); // Adds the number to the list. } else { list.push(i); } } return list; }; console.log(fizzbuzz(16)); // Leave this line for testing: module.exports = fizzbuzz;

Here’s my solution:

function fizzbuzz(n) {
let array = ;
for (let i = 1; i <= n; i++) {
if (i % 3 === 0 && i % 5 === 0) {
array.push(‘FizzBuzz’)
} else if (i % 5 === 0) {
array.push(‘Buzz’)
} else if (i % 3 === 0) {
array.push(‘Fizz’)
} else {
array.push(i);
}
}
return array;
}

console.log(fizzbuzz(16));

// Leave this line for testing:
module.exports = fizzbuzz;