Array Example

by ClarenceDowns

HTML

<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Array Example</title>

  </head>

  <body>
    <h1 class="greeting">
      Let's Meet Some of The Students From COP3530!
    </h1>

    <button class = "greeting" id = "myButton" onClick="randomStudent()">Pick One</button>
    <div class="greeting" id="output">

    </div>

  </body>

</html>

CSS

.greeting {
  color: blue;
  font-family: "Brush Script MT", "Brush Script Std", "cursive";
}

JavaScript

// Create an Array of 10 Students in COP3530
let studentArray = [
  "Mina",
  "Christopher",
  "Ret",
  "Jacob",
  "Ember",
  "Michael",
  "Patrick",
  "Aren",
  "Sean",
  "Andrew"
];

function randomStudent() {
	
let randomName = [Math.floor(Math.random()*studentArray.length)];

document.getElementById("output").innerHTML = studentArray[randomName];
}