<!--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;
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.