COP3530_Asn1_Array
Randomly retrieving name from array of classmates, then display name on screen.
by Neil Daley
HTML
<div>
Random Student Name On Click
</div>
<input type='button' id='aButton' value='Pick One' onclick='getStudentName()' />
<p id='pName' style= "color:blue; background-color:yellow"></p>
JavaScript
var studentname = []
studentname [0] ="Juan"
studentname [1] ="Amanda"
studentname [2] ="Bienvenido"
studentname [3] ="Alan"
studentname [4] ="Dennis"
studentname [5] ="Sheila"
studentname [6] ="Ebony"
studentname [7] ="James"
studentname [8] ="Brandon"
studentname [9] ="Nikolas"
function getStudentName() {
var randomName = Math.floor(Math.random() * (10)); // Use (studentname.length) if adding more student names in future.
document.getElementById('pName').innerHTML = studentname[randomName];
}