Array Example

by Peyton Hessler

HTML

<!--Below is where I create the button and give it certain qualities that I desire.-->
<input type="button" id="btnSearch" value="Pick One"
onclick="GetValue();" /> <!--This calls my function when I click the button.</q>-->
<p id="message" ></p>

JavaScript

function GetValue()
{
    var myArray= new Array("Nyle Anderson","Peyton Hessler","Morgan Southard", "Ryan Brown", "Evan Eriksen", "Lance Koontz", "Justin Leahey", "Zachary McCarthy", "Robert Mochel", "Dylan Roberts"); //Created an array named myArray where I had put ten student names to grab from.
    
    var random = myArray[Math.floor(Math.random() * myArray.length)]; 		// Here I have the element that grabs a random name from the array. By using the Math.random I am able to randomly pick a name that has been placed inside the array.
    
    document.getElementById("message").innerHTML=random;
}