I have made this code which displays a random question each time a page is refreshed or clicked. However, i want it to display not just one random question but 3 different ones which are randomized each time. How would i do this!
Thanks!
<script language="JavaScript">
var question= new Array(5)
question[0] = "Question 1"
question[1] = "Question 2"
question[2] = "Question 3"
question[3] = "Question 4 "
question[4] = "Question 5) "
question[5] = "Question 6) "
var rand_int= Math.floor(Math.random()*5);
document.write(question[rand_int]);
</script>
Firstly, I would stay away from
document.write
-- this overwrites the page each time. Instead you should append to a DOM element.Assign this
div
to a variable:You'll need a new random number each time one of the questions from the list is pulled. Define the number of questions you want to show:
Loop over the array of questions with the
questionsVisible
as the stopping point:This works.