1

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?

1
  • 1
    where do you like to get the result? Commented Dec 13, 2017 at 13:54

1 Answer 1

2

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>

Sign up to request clarification or add additional context in comments.

1 Comment

@J.DoeFoe, you could accept the answer which help you most.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.