0
我正在試圖製作一個網站,它從數組中選擇隨機的東西來做一個句子。它應該從objectArray
選擇一個隨機的項目,並通過div
與document.getElementById()
從數組中隨機選擇
代碼顯示它
<script>
var objectArray = ["computer", "iphone", "duck", "candle", "oven", "sofa", "curtain", "blanket", "star", "piano", "turtle", "fluffiness", "door", "pillow", "funny face", "lamp", "healthy heart", "rainbow", "lamp", "clock", "coat", "just luck", "stop sign", "window"];
var randObject = objectArray[Math.floor(Math.random() * objectArray.length)];
document.getElementById("Objecto").innerHTML = "randObject";
</script>
<center>
<div id="Objecto"></div>
</center>
有什麼問題嗎? – Frxstrem