-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
96 lines (81 loc) · 2.86 KB
/
app.js
File metadata and controls
96 lines (81 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
$(document).ready(function() {
var process_form = function(event){
event.preventDefault();
// $('.quiz').hide();
// $('.quiz').slideUp("fast", function() {});
var scores = [0, 0, 0, 0, 0, 0, 0 ,0];
var num_answered = 0;
$('.option input').each(function(){
if (this.checked) {
num_answered++;
if(this.value.indexOf("ba") >= 0){
scores[0]++;
}
if(this.value.indexOf("r") >= 0) {
scores[1]++;
}
if(this.value.indexOf("l") >= 0) {
scores[2]++;
}
if(this.value.indexOf("ho") >= 0) {
scores[3]++;
}
if(this.value.indexOf("m") >= 0) {
scores[4]++;
}
if(this.value.indexOf("he") >= 0) {
scores[5]++;
}
if(this.value.indexOf("bu") >= 0) {
scores[6]++;
}
if(this.value.indexOf("q") >= 0) {
scores[7]++;
}
};
});
console.log("answered: "+num_answered);
if(num_answered < 10){
$('#incomplete').show();
} else {
$('#incomplete').hide();
var houses = ["Baxter", "Reed", "Ladd", "Howell", "MacMillan", "Helmreich", "Burnett", "Quinby"];
var i = scores.indexOf(Math.max.apply(Math, scores));
var house = houses[i];
$('.house').text(house + " House");
var imageURL = "http://www.bowdoin.edu/reslife/images/"
if (house == "Burnett") {
imageURL += house + "1.jpg"
} else{
imageURL += house + ".jpg"
};
console.log(scores);
$('.results img')[0].src = imageURL;
$('.results').show();
$("html, body").animate({ scrollTop: $(document).height() }, "slow");
}
};
var reset = function(event){
$('.results').hide();
$('.quiz')[0].reset();
$("html, body").animate({ scrollTop: 0}, "slow");
};
// ~ Initial setup ~
$('.quiz').on("submit", process_form);
// Allow only one checkbox to be selected at a time
$("input:checkbox").on('click', function() {
var $box = $(this);
if ($box.is(":checked")) {
var group = "input:checkbox[name='" + $box.attr("name") + "']";
$(group).prop("checked", false);
$box.prop("checked", true);
} else {
$box.prop("checked", false);
}
});
// Results setup
$('.reset').click(reset);
$('.results').hide();
// image shouldn't be bigger than the screen
$('.results img').css("max-width", $(window).width());
});