-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
93 lines (85 loc) · 2.02 KB
/
main.js
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
var question;
var progress;
var qa;
var qb;
var qc;
var qd;
var qe;
var footer;
var cur_quest = 0;
var num_quest = 0;
var quiz = "quizzes/elements.quiz"
var data = [];
var correct = 0;
var attempted = 0;
function httpGet(theUrl){
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false );
xmlHttp.send( null );
return xmlHttp.responseText;
}
window.onload = function(){
question = document.getElementById("question");
progress = document.getElementById("progress");
qa = document.getElementById("QA");
qb = document.getElementById("QB");
qc = document.getElementById("QC");
qd = document.getElementById("QD");
qe = document.getElementById("QE");
footer = document.getElementById("footer");
var text = httpGet(quiz);
var qs = text.split("---\n");
num_quest = qs.length;
for (i = 0; i < num_quest; i++){
var ds = qs[i].split("\n");
ds.push(0);
data.push(ds);
}
update();
}
function update(){
progress.innerHTML = "Question: " + (cur_quest + 1).toString() + "/" + num_quest.toString() + "; Score: " + correct.toString() + "/" + attempted.toString();
question.innerHTML = data[cur_quest][0];
qa.innerHTML = data[cur_quest][1];
qb.innerHTML = data[cur_quest][2];
qc.innerHTML = data[cur_quest][3];
qd.innerHTML = data[cur_quest][4];
qe.innerHTML = data[cur_quest][5];
if (data[cur_quest][7] == 1){
footer.innerHTML = "The Correct Answer was "+data[cur_quest][6];
}else{
footer.innerHTML = "";
}
}
function answer(){
var html;
var answer = document.querySelector('input[name="answer"]:checked').value;
if (answer == data[cur_quest][6]){
html = "<font color=#00FF00> Correct! </font>";
if (data[cur_quest][7] == 0){
correct++;
}
}else{
html = "<font color=#FF0000> Incorrect </font>";
}
if (data[cur_quest][7] == 0){
attempted++;
data[cur_quest][7] = 1;
}
update();
footer.innerHTML = html;
}
function next(){
cur_quest++;
if (cur_quest >= num_quest){
cur_quest = 0;
}
update();
}
function prev(){
cur_quest--;
if (cur_quest < 0){
cur_quest = num_quest-1;
}
update();
}