Reputation: 75
I have an array consisting of five values as such:
var myArray = ["Hi", "Hello", "Yes", "No", "10"]
I'm trying to get a value printed on random, so i've added this:
var rand = myArray[Math.floor(Math.random() * myArray.length)];
But I'm unsure on where to put it. Anyone got better ideas on how to figure this one out?
Upvotes: 1
Views: 59
Reputation: 386883
You could assign the random string to an element of DOM.
var myArray = ["Hi", "Hello", "Yes", "No", "10"]
var rand = myArray[Math.floor(Math.random() * myArray.length)];
document.getElementById('out').innerHTML = rand;
<div id="out"></div>
Upvotes: 2