Array Example

Assignment 1

by Robert Mochel

HTML

<h1>
Assignment 1 - An Array Example
</h1>
<br>
<h3>
To see a random name:
</h3>
<br>
<button onclick="myRandom()">PICK ONE</button>
<p id="demo"></p>

JavaScript

//We have a function which includes the array as well as the number generator
function myRandom() {

//This is the array with 10 names.
var names = ["Robert", "Nyle", "Ryan", "Trishella", "Daniel", "Evan", "Fernando", "Peyton", "David", "Joeseph", "Amanda"];


//The next line prints the description of the function as well as the random array string
document.getElementById("demo").innerHTML =  "The random generated name out of the array is: " + names[Math.floor(Math.random() * 11)];
}