好吧,試圖將數組放在一起並按升序排列。我越看,我就越迷惑自己。警報提示爲「未定義」。我忽略了什麼?我在做什麼錯這個數組?
var random = new Array();
function main() {
generate();
original();
ascending(random);
}
function generate() {
document.write("Here are 25 Random Numbers:<br><br>");
for (var i = 0; i < 25; i++) {
random[i] = document.write(Math.floor(Math.random() * 100) + ", ");
}
}
function original() {
var storage = "";
for (var i = 0; i < 25; i++) {
storage += random[i] + ", ";
}
alert(storage);
}
function ascending(random) {
var tempArray = random;
var storage = "";
random.sort(function (a, b) {
return a - b
});
for (i = 0; i < 25; i++) {
storage += tempArray[i] + ", ";
}
alert("ASCENDING- " + storage);
}
我看到一個變量和四個函數。我不明白你是怎麼打電話給他們的。 – j08691 2014-11-05 20:26:34