Malj72
9/12/2017 - 6:03 AM

Multiples of 6 in given range - function

Enter the first and last number in range and recieve all the multiples of 6 + number of multiples.

function multiplesOf6(firstNumber, lastNumber) {
  
  let multipleCounter = 0,
  multipleArray = [];

  for (var i = firstNumber; i <= lastNumber ; i++) {
    if (i % 6 === 0) {
      multipleArray.push(" " + i);
      multipleCounter++;
    }    
  }
  return `There are ${multipleCounter} multiples of 6: ${multipleArray}.`;
}

console.log(multiplesOf6(1, 150));