something in my code is meaning that I am getting an array printed which contains only undefined values, not the random numbers I am expecting.
My code is below:
function List(max, min, numLists, numItems) {
this.max = max,
this.min = min,
this.numLists = numLists,
this.numItems = numItems,
this.generateLists = function () {
var fullArray = [];
var completeArray = [];
for (i = this.min; i < this.max; i++) {
fullArray.push(i);
}
for (i = 0; i < numItems; i++) {
var randomItem = Math.floor(Math.random() * (1 + (this.max - this.min)));
completeArray.push(fullArray[randomItem]);
}
console.log(completeArray);
}
}
var newList = new List(12, 100, 1, 15);
newList.generateLists();
The code is supposed to print a random list of number between the min and max values. I'm getting an array with 15 values in, but they are all undefined. I'm guessing this mean there is something wrong with my first 'for' loop?
If anyone has any suggestions on how I could make this better please do criticise!
Thanks in advance.