-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathquiz.html
91 lines (85 loc) · 3.69 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
<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>Ukrainianvalues Quiz</title>
<link rel="icon" type="x-icon" href="icon.png">
<link rel="shortcut icon" type="x-icon" href="icon.png">
<meta charset="utf-8">
</head>
<body>
<script type="application/javascript"
src="questions.js">
</script>
<h1>Ukrainianvalues</h1>
<hr>
<h2 style="text-align:center;" id="question-number">Завантаження...</h2>
<p class="question" id="question-text"></p>
<button class="button stronglyAgree" onclick="next_question( 1.0)">Повністю погоджуюся</button> <br>
<button class="button agree" onclick="next_question( 0.5)">Погоджуюся</button> <br>
<button class="button neutral" onclick="next_question( 0.0)">Нейтрально</button> <br>
<button class="button disagree" onclick="next_question(-0.5)">Не погоджуюся</button> <br>
<button class="button stronglyDisagree" onclick="next_question(-1.0)">Зовсім не погоджуюся</button> <br>
<button class="small_button" onclick="prev_question()" id="back_button">Назад</button>
<button class="small_button_off" id="back_button_off">Назад</button><br>
<!-- JavaScript for the test itself -->
<script>
var max_econ, max_dipl, max_govt, max_scty; // Max possible scores
max_econ = max_dipl = max_govt = max_scty = 0;
let econ_array = new Array(questions.length);
let dipl_array = new Array(questions.length);
let govt_array = new Array(questions.length);
let scty_array = new Array(questions.length);
var qn = 0; // Question number
init_question();
for (var i = 0; i < questions.length; i++) {
max_econ += Math.abs(questions[i].effect.econ)
max_dipl += Math.abs(questions[i].effect.dipl)
max_govt += Math.abs(questions[i].effect.govt)
max_scty += Math.abs(questions[i].effect.scty)
}
function init_question() {
document.getElementById("question-text").innerHTML = questions[qn].question;
document.getElementById("question-number").innerHTML = "Питання " + (qn + 1) + " з " + (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) {
econ_array[qn] = mult*questions[qn].effect.econ
dipl_array[qn] = mult*questions[qn].effect.dipl
govt_array[qn] = mult*questions[qn].effect.govt
scty_array[qn] = mult*questions[qn].effect.scty
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_econ = econ_array.reduce((a, b) => a + b, 0)
let final_dipl = dipl_array.reduce((a, b) => a + b, 0)
let final_govt = govt_array.reduce((a, b) => a + b, 0)
let final_scty = scty_array.reduce((a, b) => a + b, 0)
location.href = `results.html`
+ `?e=${calc_score(final_econ,max_econ)}`
+ `&d=${calc_score(final_dipl,max_dipl)}`
+ `&g=${calc_score(final_govt,max_govt)}`
+ `&s=${calc_score(final_scty,max_scty)}`
}
</script>
</body>