-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
158 lines (137 loc) · 4.31 KB
/
script.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
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
const getStarted = document.getElementById("get-started");
const qScript = document.getElementById("qScript");
const opt1 = document.getElementById("opt1");
const opt2 = document.getElementById("opt2");
const opt3 = document.getElementById("opt3");
const opt4 = document.getElementById("opt4");
const nextQues = document.getElementById("next-question");
const totalScore = document.getElementById("your-score");
let score = 0;
let questionArray = 0;
getStarted.addEventListener("click", startQuiz);
function startQuiz() {
console.log(questionArray);
opt1.style.background = "white";
opt2.style.background = "white";
opt3.style.background = "white";
opt4.style.background = "white";
document.getElementById("get-started").style.display = "none";
document.getElementById("content").style.display = "block";
question1();
}
function question1() {
// console.log(questionArray);
document.getElementById("img").src = "images/pic1.jpg";
qScript.textContent = qArray[0].question;
opt1.textContent = qArray[0].opt1;
opt2.textContent = qArray[0].opt2;
opt3.textContent = qArray[0].opt3;
opt4.textContent = qArray[0].opt4;
opt1.addEventListener("click", opt1Clicked);
}
function opt1Clicked() {
score++;
}
function answerReveal() {
if (questionArray === 0) {
// console.log(questionArray);
questionArray++;
// console.log(questionArray);
opt1.style.background = "green";
opt2.style.background = "red";
opt3.style.background = "red";
opt4.style.background = "red";
nextQuestion1();
} else if (questionArray === 1) {
// console.log(questionArray);
questionArray++;
// console.log(questionArray);
opt1.style.background = "red";
opt2.style.background = "green";
opt3.style.background = "red";
opt4.style.background = "red";
nextQuestion2();
} else {
// console.log(questionArray);
opt1.style.background = "red";
opt2.style.background = "red";
opt3.style.background = "red";
opt4.style.background = "green";
yourScore();
}
}
function nextQuestion1() {
document.getElementById("next-question").style.display = "block";
nextQues.addEventListener("click", question2);
}
function question2() {
opt1.removeEventListener("click", opt1Clicked);
document.getElementById("img").src = "images/pic2.jpg";
opt1.style.background = "white";
opt2.style.background = "white";
opt3.style.background = "white";
opt4.style.background = "white";
document.getElementById("next-question").style.display = "none";
qScript.textContent = qArray[1].question;
opt1.textContent = qArray[1].opt1;
opt2.textContent = qArray[1].opt2;
opt3.textContent = qArray[1].opt3;
opt4.textContent = qArray[1].opt4;
opt2.addEventListener("click", opt2Clicked);
}
function opt2Clicked() {
score++;
}
function nextQuestion2() {
document.getElementById("next-question").style.display = "block";
nextQues.addEventListener("click", question3);
}
function question3() {
opt2.removeEventListener("click", opt2Clicked);
document.getElementById("img").src = "images/pic3.jpg";
qScript.textContent = qArray[2].question;
opt1.textContent = qArray[2].opt1;
opt2.textContent = qArray[2].opt2;
opt3.textContent = qArray[2].opt3;
opt4.textContent = qArray[2].opt4;
opt4.addEventListener("click", opt4Clicked);
}
function opt4Clicked() {
score++;
}
function yourScore() {
document.getElementById("your-score").style.display = "block";
totalScore.addEventListener("click", finalScreen);
}
function finalScreen() {
document.getElementById("content").style.display = "none";
document.getElementById("img").src = "images/splash.jpg";
document.getElementById("blurb").textContent = "YOU SCORED";
document.getElementById("welldone").style.display = "block";
document.getElementById("final").style.display = "block";
document.getElementById("final").textContent = score;
}
let qArray = [
{
question: "What kind of animal is this?",
opt1: "Three-Toed Sloth",
opt2: "African Elephant",
opt3: "Sea Otter",
opt4: "Chimpanzee",
},
{
question:
"Where in the world would you most likely find one of these animals?",
opt1: "New Zealand",
opt2: "Canada",
opt3: "India",
opt4: "South Africa",
},
{
question: "What colour is hippopotamus milk?",
opt1: "Green",
opt2: "White",
opt3: "Blue",
opt4: "Pink",
},
];