<p id =message> This button will select a student randomly from a list
<br><br>
<input type='button' id='myButton' value='Pick One' onClick="chooseStudent()" />
</p>
<div id="output">
</div>
<!--
<div id="output2">
</div>
-->
JavaScript
var students =
[
"Andrew", "Casey", "Charlene", "Charlotte", "Che",
"Christian", "Christoph", "Clayton", "Daniel", "David"
];
function chooseStudent() {
var random = Math.floor(Math.random() * 10)
document.getElementById("output").innerHTML =
students[random];
// This portion was for testing the output of the random variable
// document.getElementById("output2").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.