-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
173 lines (141 loc) · 4.16 KB
/
index.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<html>
<head>
<title>Question Bank</title>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
overflow-y: scroll;
}
main {
width: 960px;
max-width: 80%;
margin: 0 auto;
}
img {
width: 100%;
height: auto;
}
.question, .answer {
text-align: center;
border: 2px solid black;
}
button {
display: block;
margin: 16px auto;
}
/* Goto question styling */
.goto {
text-align: center;
}
.goto * {
display: inline-block;
vertical-align: middle;
}
</style>
</head>
<body>
<main>
<h1>MAE2401 Questions</h1>
<h2 class="question_number"></h2>
<div class="question"></div>
<!-- Answer button -->
<button onclick="show()" class="show">Show Answer</button>
<button onclick="hide()" class="hide">Hide Answer</button>
<button onclick="next()">Next Question</button>
<!-- Goto question -->
<div class="goto">
<label for="question_number">Go to question:</label>
<input type="number" id="question_number" name="question_number" min="1" max="987" value="">
<button onclick="goto()">Go</button>
</div>
<div class="answer" style="display: none;"></div>
</main>
<script>
prev_questions = [];
next_questions = [];
n_questions = 987;
// Create image element
q_img_element = document.createElement("img");
a_img_element = document.createElement("img");
// Add image to document
document.querySelector(".question").appendChild(q_img_element);
document.querySelector(".answer").appendChild(a_img_element);
function show() {
document.querySelector(".answer").style.display = "block";
document.querySelector(".show").style.display = "none";
document.querySelector(".hide").style.display = "block";
}
function hide() {
document.querySelector(".answer").style.display = "none";
document.querySelector(".show").style.display = "block";
document.querySelector(".hide").style.display = "none";
}
hide();
function goto() {
// Clear next and previous questions
next_questions = [];
prev_questions = [];
// Get question number
q_idx = document.getElementById("question_number").value;
// Change question
q_img = "questions/question_" + q_idx.toString().padStart(3, '0') + ".png";
a_img = "questions/answers_" + q_idx.toString().padStart(3, '0') + ".png";
q_img_element.src = q_img;
a_img_element.src = a_img;
document.getElementsByClassName("question_number")[0].innerHTML = "Question " + q_idx.toString();
}
// Also run goto when enter is pressed
document.getElementById("question_number").addEventListener("keyup", function(event) {
if (event.keyCode === 13) {
event.preventDefault();
goto();
}
});
function next() {
// Change question
if (next_questions.length == 0) {
q_idx = Math.floor(Math.random() * n_questions) + 1;
} else {
q_idx = next_questions.pop();
}
// Hide answers
hide()
// Save question index
prev_questions.push(q_idx);
// Change question
q_img = "questions/question_" + q_idx.toString().padStart(3, '0') + ".png";
a_img = "questions/answers_" + q_idx.toString().padStart(3, '0') + ".png";
q_img_element.src = q_img;
a_img_element.src = a_img;
document.getElementsByClassName("question_number")[0].innerHTML = "Question " + q_idx.toString();
document.getElementById("question_number").value = q_idx;
}
function prev() {
if (prev_questions.length == 0) {return;}
if (next_questions.length == 0) {prev_questions.pop();}
// Save next question index
next_questions.push(q_idx);
q_idx = prev_questions.pop();
// Hide answers
hide()
// Change question
q_img = "questions/question_" + q_idx.toString().padStart(3, '0') + ".png";
a_img = "questions/answers_" + q_idx.toString().padStart(3, '0') + ".png";
q_img_element.src = q_img;
a_img_element.src = a_img;
document.getElementsByClassName("question_number")[0].innerHTML = "Question " + q_idx.toString();
document.getElementById("question_number").value = q_idx;
}
next()
// Map arrows to next and previous
document.body.onkeyup = function(e) {
if (e.keyCode == 39) {
next();
}
if (e.keyCode == 37) {
prev();
}
}
</script>
</body>
</html>