Skip to content

Instantly share code, notes, and snippets.

@purplecones
Last active May 3, 2017 11:19
Show Gist options
  • Select an option

  • Save purplecones/750a28f74197cdd853c3eae7b146bbb1 to your computer and use it in GitHub Desktop.

Select an option

Save purplecones/750a28f74197cdd853c3eae7b146bbb1 to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=750a28f74197cdd853c3eae7b146bbb1
<!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 four random teachers</button>
<div id="teacherDisplay"></div>
</body>
</html>
{"enabledLibraries":["jquery"]}
var teachers = [
"Brian",
"Mirza",
"Carol",
"Eliza",
"Karl",
"Jonathan",
"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 and display them on the screen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment