-
Notifications
You must be signed in to change notification settings - Fork 1
/
quiz.html
143 lines (133 loc) · 4.24 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<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>Kuis 8nilai</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>8nilai</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)">
Sangat Setuju
</button>
<br />
<button class="button agree" onclick="next_question( 0.5)">Setuju</button>
<br />
<button class="button neutral" onclick="next_question( 0.0)">
Netral/Tidak Yakin
</button>
<br />
<button class="button disagree" onclick="next_question(-0.5)">
Tidak Setuju
</button>
<br />
<button class="button stronglyDisagree" onclick="next_question(-1.0)">
Sangat Tidak Setuju
</button>
<br />
<button class="small_button" onclick="prev_question()" id="back_button">
Kembali
</button>
<button class="small_button_off" id="back_button_off">Kembali</button><br />
<footer>
Re-design by <a href="https://github.com/nomadkode">nomadkode</a>
</footer>
<!--* GSAP Library-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.6.1/gsap.min.js"></script>
<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 =
'Pertanyaan ke ' + (qn + 1) + ' dari ' + 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)}`;
}
// GSAP Script
gsap.from('h1', {
duration: 1.5,
delay: 0.5,
y: -200,
opacity: 0,
});
gsap.from('h2', {
duration: 1.5,
delay: 1,
x: -200,
opacity: 0,
});
gsap.from('.question', {
duration: 1.5,
delay: 1.5,
x: 200,
opacity: 0,
});
gsap.from('.button', {
duration: 1.5,
delay: 2,
y: 200,
opacity: 0,
});
</script>
</body>