Skip to content

Instantly share code, notes, and snippets.

@purplecones
Created May 2, 2017 18:16
Show Gist options
  • Select an option

  • Save purplecones/8b0e669ad0581cdbb0d3fd422001625e to your computer and use it in GitHub Desktop.

Select an option

Save purplecones/8b0e669ad0581cdbb0d3fd422001625e to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=8b0e669ad0581cdbb0d3fd422001625e
<!DOCTYPE html>
<html>
<head>
<title>Class Randomizer</title>
</head>
<body>
<h1>Randomly Choose a Student</h1>
<button id="studentButton">Click me to pick one random student</button>
<div id="studentDisplay"></div>
<h1>Randomly Choose a Teacher</h1>
<button id="teacherButton">Click me to pick two random teachers</button>
<div id="teacherDisplay"></div>
</body>
</html>
{"enabledLibraries":["jquery"]}
var teachers = [
"Brian",
"Mirza",
"Carol",
"Eliza",
"Karl",
"Christian",
"Melissa"
];
var students = [
"Haoxi", "Maria Lucia", "Bhutika",
"Sami", "Jonathan", "Miguel",
"Hassany", "Yuna", "Margaux",
"Diego", "Laura", "Zhindel",
"Isaac", "Milena", "Luka",
"Linhong", "Edwin","Adrian", "Fior",
"Mohamed", "Yancy", "Mahadi",
"Sallam", "Oumar", "Griselda",
"Maria Gomez", "Marco"
];
$('#studentButton').click(function () {
// get a random number
// how do we fix this to pick from all students from the student array?
var randomNumber = Math.floor(Math.random() * 2);
// get a random student
var randomStudent = students[randomNumber];
// display student name
$('#studentDisplay').append('<p>' + randomStudent + '</p>');
});
// USING LOOPS pick four random teachers from the teachers array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment