Skip to content

Instantly share code, notes, and snippets.

@sandbergja
Created May 11, 2016 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandbergja/0599ea655bab2b01cccd16594369f70f to your computer and use it in GitHub Desktop.
Save sandbergja/0599ea655bab2b01cccd16594369f70f to your computer and use it in GitHub Desktop.
personality survey about the 1968 East LA Walkouts
<!doctype html>
<html lang="en">
<!-- To add questions to this quiz, go to line # 160, near the bottom of this file -->
<head>
<meta charset="utf-8">
<title>Personality quiz: East L.A. walkouts</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
</head>
<body onload="print_all_questions();" style="background: #F74;">
<div id="content" class="col-xs-8 col-xs-offset-2" style="background: #FFF;padding:20px;">
<h1>Imagine yourself in history...</h1>
<form id="questions"></form>
<br /><br /><br />
<button type="button" class="btn btn-success" onclick="show_results();">Who am I?</button>
<button type="button" class="btn btn-default" onclick="location.reload();">Start over</button>
<div id="results"></div>
<script>
// This is where the code starts
var Person = class {
constructor(name, image) {
this.name = name;
this.image = image;
this.points = 0;
this.code = name.charAt(0);
}
add_points(number) {
this.points = this.points + number;
}
};
var Question = class {
constructor(question) {
this.question = question;
this.answers = [];
}
add_answer(text, first_name, number_of_points) {
var temp = new Answer(text, first_name, number_of_points);
this.answers.push(temp);
}
print(id) {
var question_to_print = document.createElement('fieldset');
var question_text = document.createTextNode(this.question);
question_to_print.appendChild(question_text);
question_to_print.appendChild(document.createElement('br'));
var select = document.createElement('select');
select.class = "form-control";
select.id = id;
for (var j = 0; j < this.answers.length; j++) {
var option = document.createElement('option');
var answer_text = document.createTextNode(this.answers[j].text);
option.setAttribute('number_of_points', this.answers[j].number_of_points);
option.setAttribute('person_code', this.answers[j].first_name.code);
option.appendChild(answer_text);
select.appendChild(option);
}
question_to_print.appendChild(select);
var form = document.getElementById("questions");
form.appendChild(question_to_print);
}
};
var questions_to_load = [];
function print_all_questions() {
for (var i = 0; i < questions_to_load.length; i++) {
questions_to_load[i].print(i);
}
}
function show_results() {
for (i = 0; i < questions_to_load.length; i++) {
current_question = document.getElementById(i);
var point_delta = (current_question.options[current_question.selectedIndex].getAttribute('number_of_points'));
switch (current_question.options[current_question.selectedIndex].getAttribute('person_code')) {
case 'C':
carlos.add_points(point_delta);
break;
case 'M':
moctesuma.add_points(point_delta);
break;
case 'P':
paula.add_points(point_delta);
break;
case 'S':
sal.add_points(point_delta);
break;
}
}
winner = carlos;
if (parseInt(moctesuma.points) > parseInt(winner.points)) {
winner = moctesuma;
}
if (parseInt(paula.points) > parseInt(winner.points)) {
winner = paula;
}
if (parseInt(sal.points) > parseInt(winner.points)) {
winner = sal;
}
var winner_to_print = document.getElementById("results");
var name_to_print = document.createTextNode(winner.name);
var header_to_print = document.createElement('h2');
header_to_print.appendChild(name_to_print);
winner_to_print.appendChild(header_to_print);
var img_to_print = document.createElement('img');
img_to_print.src = winner.image;
winner_to_print.appendChild(img_to_print);
}
var Answer = class {
constructor(text, first_name, number_of_points) {
this.text = text;
this.first_name = first_name;
this.number_of_points = number_of_points;
}
}
var moctesuma = new Person(
"Moctesuma Esparza",
"http://ia.media-imdb.com/images/M/MV5BNjA3NTE5Njc3N15BMl5BanBnXkFtZTgwMjkwOTUxMDE@._V1_UX214_CR0,0,214,317_AL_.jpg"
);
var sal = new Person(
"Sal Castro",
"http://www.calstatela.edu/sites/default/files/univ/ppa/publicat/today/images/CASTRO-2.jpg"
);
var carlos = new Person (
"Carlos Muñoz, Jr.",
"http://www.apbspeakers.com/sites/default/files/imagecache/apb_speaker_page/speaker/image/sp1005741_0.png"
);
var paula = new Person (
"Paula Crisostomo",
"http://www.oxy.edu/sites/default/files/assets/ICA/Paula-Web.jpg"
);
//////////////////////////////////////////////
// This is where you can type the questions //
//////////////////////////////////////////////
// Example question
// Your questions go below here
var myQuestion = new Question("Who helps you when you have to do something difficult?");
myQuestion.add_answer("My mother", paula, 70);
myQuestion.add_answer("Other people at school", moctesuma, 5);
myQuestion.add_answer("My dad", sal, 50);
questions_to_load.push(myQuestion);
</script>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment