forked from 8values/8values.github.io
-
Notifications
You must be signed in to change notification settings - Fork 7
/
quiz.html
109 lines (101 loc) · 4.32 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
<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>8values问题</title>
<link rel="icon" type="x-icon" href="icon.png">
<link rel="shortcut icon" type="x-icon" href="icon.png">
<meta charset="utf-8">
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: "ca-pub-45340418289011776",
enable_page_level_ads: true
});
</script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-5CTBKRVD08"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-5CTBKRVD08');
</script>
<!-- Clarity tracking code for https://songyon.github.io/8valuescn/ -->
</head>
<body>
<script type="application/javascript"
src="questions.js">
</script>
<h1>8values中文版</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>