-3

I have written a function that generates different numbers each time it is called. Now I want it to genarate say 50 different numbers and then push it into an array. How do I go about it? This is the code below:

function generateRandomNumbers() {
    let randomArray = [];
    let digits = Math.floor(Math.random() * 900000000) + 100000000;
    digits = `0${digits}`;
    // Last task is to push 50 random digits into the array;

    return randomArray;
}
console.log(generateRandomNumbers());
danoseun
  • 69
  • 2
  • 9
  • @Ele All positive, actually I have generated the numbers. I just need to push 50 different instances into an array. – danoseun Sep 29 '18 at 13:43
  • @Sujit Agarwal I don't understand why you guys usually conclude questions asked here are assignments – danoseun Sep 29 '18 at 13:57

1 Answers1

1

You need to do something like this:

function generateRandomNumbers(howMany) {
  let arr = [];
  for(let i = 0; i <= howMany; i++)
  {
    let digits = Math.floor(Math.random() * 900000000) + 100000000;
    digits = `0${digits}`;
    arr.push(digits);
  }
  
  return arr;
}

let randomArray = generateRandomNumbers(50);

console.log(randomArray);
Stuart
  • 6,630
  • 2
  • 24
  • 40