function randomize(){
var maps =["Aztec","Cache","Cobblestone","Dust","DustII","Inferno",
"Mirage","Nuke","Overpass","Train","Vertigo","Assault","Italy","Militia","Office,"];
var randommap = maps[math.floor(math.random() * maps.lenth)];
var randommap = document.getElementById("map").innerHTML = randommap;
}
答案 0 :(得分:1)
这是一个非常简洁的问题。同样如此,这是一个简洁但构造良好的答案:
var maps = ['Aztec', 'Cache', 'Cobblestone', 'Dust',
'DustII', 'Inferno', 'Mirage', 'Nuke', 'Overpass',
'Train', 'Vertigo', 'Assault', 'Italy', 'Militia',
'Office'];
function randomItem(list) {
var randomIndex = Math.floor(Math.random() * list.length);
return list[randomIndex];
}
var mapEl = document.getElementById('map');
mapEl.onclick = function() {
mapEl.innerHTML = randomItem(maps);
};

<button id="map">Go!</button>
&#13;