jeudi 24 mars 2016

Random Pick From Array

I am trying to make a website where it selects random things from arrays to make a sentence. It is supposed to pick a random item from objectArray and display it through a div with document.getelementbyid

Code

<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>




Aucun commentaire:

Enregistrer un commentaire