forked from 8values/8values.github.io
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathquiz.html
113 lines (102 loc) · 4.22 KB
/
quiz.html
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<head>
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:400,700" rel="stylesheet">
<link href='style.css' rel='stylesheet' type='text/css'>
<title>IndieValues</title>
<link rel="icon" type="x-icon" href="icon.png">
<link rel="shortcut icon" type="x-icon" href="icon.png">
<meta charset="utf-8">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-VZ0VD0LL75"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-VZ0VD0LL75');
</script>
</head>
<body>
<script type="application/javascript"
src="questions.js">
</script>
<h1>IndieValues</h1>
<hr>
<h2 style="text-align:center;" id="question-number">Loading...</h2>
<p class="question" id="question-text"></p>
<button class="button stronglyAgree" onclick="next_question( 1.0)">Strongly Like</button> <br>
<button class="button agree" onclick="next_question( 0.5)">Like</button> <br>
<button class="button neutral" onclick="next_question( 0.0)">Neutral/Unsure/Never Heard Them</button> <br>
<button class="button disagree" onclick="next_question(-0.5)">Dislike</button> <br>
<button class="button stronglyDisagree" onclick="next_question(-1.0)">Strongly Dislike</button> <br>
<button class="small_button" onclick="prev_question()" id="back_button">Back</button>
<button class="small_button_off" id="back_button_off">Back</button><br>
<!-- JavaScript for the test itself -->
<script>
var max_popl, max_peri, max_comp, max_inov; // Max possible scores
max_popl = max_peri = max_comp = max_inov = 0;
let popl_array = new Array(questions.length);
let peri_array = new Array(questions.length);
let comp_array = new Array(questions.length);
let inov_array = new Array(questions.length);
var qn = 0; // Question number
shuffleArray(questions);
init_question();
for (var i = 0; i < questions.length; i++) {
max_popl += Math.abs(questions[i].effect.popl)
max_peri += Math.abs(questions[i].effect.peri)
max_comp += Math.abs(questions[i].effect.comp)
max_inov += Math.abs(questions[i].effect.inov)
}
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
function init_question() {
document.getElementById("question-text").innerHTML = questions[qn].question;
document.getElementById("question-number").innerHTML = "Artist " + (qn + 1) + " of " + (questions.length);
if (qn == 0) {
document.getElementById("back_button").style.display = 'none';
document.getElementById("back_button_off").style.display = 'block';
} else {
document.getElementById("back_button").style.display = 'block';
document.getElementById("back_button_off").style.display = 'none';
}
}
function next_question(mult) {
popl_array[qn] = mult*questions[qn].effect.popl
peri_array[qn] = mult*questions[qn].effect.peri
comp_array[qn] = mult*questions[qn].effect.comp
inov_array[qn] = mult*questions[qn].effect.inov
qn++;
if (qn < questions.length) {
init_question();
} else {
results();
}
}
function prev_question() {
if (qn == 0) {
return;
}
qn--;
init_question();
}
function calc_score(score,max) {
return (100*(max+score)/(2*max)).toFixed(1)
}
function results() {
let final_popl = popl_array.reduce((a, b) => a + b, 0)
let final_peri = peri_array.reduce((a, b) => a + b, 0)
let final_comp = comp_array.reduce((a, b) => a + b, 0)
let final_inov = inov_array.reduce((a, b) => a + b, 0)
location.href = `results.html`
+ `?p=${calc_score(final_popl,max_popl)}`
+ `&e=${calc_score(final_peri,max_peri)}`
+ `&c=${calc_score(final_comp,max_comp)}`
+ `&i=${calc_score(final_inov,max_inov)}`
}
</script>
</body>