samedi 1 septembre 2018

Random Array with min/max

I need to create a two arrays. One with 24 random numbers between 5 and 20. The second with 24 random numbers between 1 and 10. I think I'm on the right track with creating the arrays but can't get the minimum of 5 & 1 to stick. Here's my code:

var volts = [];

for (var i = 5; i < 29; i++)
{
  voltage = Math.floor(Math.random() * 20);
  volts.push(voltage);
}

var j = 5;
while( j < volts.length)
{
  console.log(volts[j]);
  j++;
}

var amps = [];

for (var t = 1; t < 10; t++)
{
  amppopulation = Math.floor(Math.random() * 10);
  amps.push(amppopulation);
}

var g = 0;
while( g < amps.length) {
  console.log([t]);
  t++;




Aucun commentaire:

Enregistrer un commentaire