Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Apr 2012
    Posts
    38
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Help with listing random shuffle

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

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,969
    Thanks
    56
    Thanked 557 Times in 554 Posts
    ignoring the deprected font tag, this seems simpler:

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

  • Users who have thanked xelawho for this post:

    CSwrestler (04-29-2012)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •