...

View Full Version : Help with listing random shuffle



CSwrestler
04-29-2012, 04:29 AM
is there a way to take my random shuffle script that displays the array like this

red, yellow, blue, green, black, grey

and make it so that it would list them like this

red
yellow
blue
green
black
grey


<script type="text/javascript">
function myFunction()
{
document.getElementById("demo").style.display="block";

var myarray=["red","blue", "yellow", "green","black", "grey"]
myarray.sort(function() {return 0.5 - Math.random()})
var x=document.getElementById("demo").innerHTML=myarray;
var t=setTimeout(alertMsg,10000);
}

function alertMsg()
{
document.getElementById("demo").style.display="none";
}
</script>




<button onclick="myFunction()">Twister Drill</button>

<font size="5" color="white">
<p id="demo"><br/></p>
</font>

xelawho
04-29-2012, 05:00 AM
ignoring the deprected font tag, this seems simpler:



<body>
<script type="text/javascript">
function myFunction()
{
var thediv=document.getElementById("demo")

var myarray=["red","blue", "yellow", "green","black", "grey"]
myarray.sort(function() {return 0.5 - Math.random()})
for (var i = 0; i < myarray.length; i++) {
thediv.innerHTML+=myarray[i]+"<br>";
}
var t=setTimeout(function(){thediv.innerHTML=""},10000);
}

</script>

<button onclick="myFunction()">Twister Drill</button>

<font size="5" color="black">
<p id="demo"><br/></p>
</font>
</body>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum