jeudi 24 septembre 2015

Create 3 random names from array to a element

God I love this website. So many awesome ppl!

So, I got this far that I can get 1 random name from the array. But now I want 3 different names every time, aaaand I'm stuck -_^

Anyone want to point out my lack of knowledge with their supreme awesomeness? :D Thanks in advance <3

The JS

     <script> 

window.onload = funkytown;

function funkytown() {
    document.getElementById("btn").onclick = name;
}

function name() {

        var students = ["Mike","Nick","Slagathor","Banana","Rick","Astley","Rock","JW","pronax"];
        var randomize = students.splice(Math.floor(Math.random() * students.length), 1);

        var html = "Random names: ";

        document.getElementById("text").innerHTML = html + randomize;


     }
     </script>

the HTML

<span id="text"></span>
<input type="button" id="btn" value="Randomize!" />




Aucun commentaire:

Enregistrer un commentaire