我在for循環中遇到了一些問題。當我運行代碼時,函數似乎只運行一次,因爲顯示的是隨機列表,但不是指定的預期編號。使用for循環循環函數的問題
任何人都可以幫我嗎?
function List(max,min,numLists,numItems){
this.max = max,
this.min = min,
this.numLists = numLists,
this.numItems = numItems,
this.generateList = function(){
var fullArray = [];
var completeArray = [];
var numItems = this.numItems
//create an array of integers between min and max values
for (i = this.min ; i<(this.max+1) ; i++) {
fullArray.push(i);
}
//select a random value from array of integers and add to new array
for (j = 0 ; j<numItems ; j++) {
var randomItem = Math.floor(Math.random() * (fullArray.length));
completeArray.push(fullArray[randomItem]);
}
//write new random list
document.write(completeArray);
}
this.generateMultipleLists = function() {
\t var numLists = this.numLists;
\t //loop list creation to create multiple list arrays
\t for (i=0 ; i<numLists ; i++){
\t this.generateList();
\t }
}
}
var newList = new List (100 , 12 , 7,15);
newList.generateMultipleLists();
需要知道預期的輸出,以及爲什麼你的程序輸出是錯誤的,如果我們要幫你 – NibblyPig
道歉,我是新來的,它現在全部排序雖然 – Wormdog1