Created
December 16, 2014 22:37
-
-
Save awavering/53b5cbee217179c17407 to your computer and use it in GitHub Desktop.
BSD Faces - Quiz Mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Helpers | |
//Random integer in range | |
function random_int(min, max) { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} | |
//Get employee count | |
var employee_count = $("#count").text().split(" ")[0]; | |
//Get all employee names | |
var bsd=[]; | |
var employees=[]; | |
$("article.headshot").each(function(){ | |
var fullname = $("h4:first",this).text(); | |
var img = $("img",this).attr("src") | |
var employee = {"name":fullname, "img":img}; | |
bsd.push(employee); | |
}); | |
correct=0; | |
incorrect=0; | |
//build interface | |
$(".page-title h1").html('BSD Faces - Quiz Mode'); | |
$(".page-title p").html('Think you know your coworkers? Take the quiz!'); | |
$(".content").hide(); | |
//Start quiz button | |
$(".stage").prepend('<center><a id="start_button"><h1>Start!</h1></a></center>'); | |
$("#start_button").css({"cursor":"pointer"}); | |
$(".stage .three-column").hide(); | |
$('#start_button').click(start_quiz); | |
//Display options | |
function start_quiz() { | |
//select 4 random employees, turn into array' | |
employees=[]; | |
employees.push(bsd[random_int(0,employee_count)],bsd[random_int(0,employee_count)],bsd[random_int(0,employee_count)]); | |
$('#start_button').hide(); | |
$(".stage .three-column:eq(0)").html(''); | |
$(".stage .three-column:eq(1)").html(''); | |
$(".stage .three-column:eq(2)").html(''); | |
$("#photo").remove(); | |
console.log('Starting Quiz'); | |
$(".stage .three-column").show(); | |
mystery_employee = []; | |
mystery_employee.push(employees[random_int(0, 2)]); | |
$(".stage").prepend('<center id="photo"><img src='+mystery_employee[0].img+' height="200" width="200" style="padding-bottom: 50px;"></img></center>'); | |
$(".stage .three-column:eq(0)").html('<center><a id="a_1"><h3>'+employees[0].name+'</h3></a></center>'); | |
$(".stage .three-column:eq(1)").html('<center><a id="a_2"><h3>'+employees[1].name+'</h3></a></center>'); | |
$(".stage .three-column:eq(2)").html('<center><a id="a_3"><h3>'+employees[2].name+'</h3></a></center>'); | |
$(".stage a").css({"cursor":"pointer"}); | |
total=correct+incorrect; | |
$(".page-title p").html('<h3>Score: '+correct+'/'+total+'</h3>'); | |
$(".three-column h3").click(function() { | |
var chosen_name=$(this).text(); | |
console.log(chosen_name); | |
if(chosen_name==mystery_employee[0].name){ | |
//if right | |
//keep score | |
correct=correct+1; | |
console.log('correct'); | |
//display message and refresh | |
$(".stage #question a").remove(); | |
start_quiz(); | |
} else { | |
//if wrong | |
//keep score | |
incorrect=incorrect+1; | |
console.log('incorrect'); | |
//display message and refresh | |
start_quiz(); | |
} | |
}); | |
} | |
//check answer | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Warning - this might not even work anymore, I don't remember if I did any more local dev.