-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscript.js
More file actions
143 lines (112 loc) · 3.96 KB
/
script.js
File metadata and controls
143 lines (112 loc) · 3.96 KB
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
$(document).ready(function(){
//Start Section
let start = document.querySelector("#start");
//guide Section
let guide = document.querySelector("#guide");
let exit = document.querySelector("#exit");
let continueBtn = document.querySelector("#continue");
//Quiz Section
let quiz = document.querySelector("#quiz");
//question Section
let questionNo = document.querySelector("#questionNo");
let questionText = document.querySelector("#questionText");
//Multiple Choices Of Questions
let option1 = document.querySelector("#option1");
let option2 = document.querySelector("#option2");
let option3 = document.querySelector("#option3");
let option4 = document.querySelector("#option4");
//correct and next Button
let total_correct = document.querySelector("#total_correct");
let next_question = document.querySelector("#next_question");
//Result Section
let result = document.querySelector("#result");
let points = document.querySelector("#points");
let quit = document.querySelector("#quit");
let startAgain = document.querySelector("#startAgain");
//Get All 'H4' From Quiz Section (MCQS)
let choice_que = document.querySelectorAll(".choice_que");
let index = 0;
//total points
let correct = 0;
//store Answer Value
let UserAns = undefined;
//what happen when 'Start' Button Will Click
start.addEventListener("click", () => {
start.style.display = "none";
guide.style.display = "block";
});
//what happen when 'Exit' Button Will Click
exit.addEventListener("click", () => {
start.style.display = "block";
guide.style.display = "none";
});
let loadData = () => {
questionNo.innerText = index + 1 + ". ";
questionText.innerText = MCQS[index].question;
option1.innerText = MCQS[index].choice1;
option2.innerText = MCQS[index].choice2;
option3.innerText = MCQS[index].choice3;
option4.innerText = MCQS[index].choice4;
}
loadData();
//what happen when 'Continue' Button Will Click
continueBtn.addEventListener("click", () => {
quiz.style.display = "block";
guide.style.display = "none";
// remove All Active Classes When Continue Button Will Click
choice_que.forEach(removeActive => {
removeActive.classList.remove("active");
})
total_correct.innerHTML = `${correct = 0} Out Of ${MCQS.length} Questions`;
});
choice_que.forEach((choices, choiceNo) => {
choices.addEventListener("click", () => {
choices.classList.add("active");
//check answer
if (choiceNo === MCQS[index].answer) {
correct++;
} else {
correct += 0;
}
//disable All Options When User Select An Option
for (i = 0; i <= 3; i++) {
choice_que[i].classList.add("disabled");
}
})
});
////what happen when 'Next' Button Will Click
next_question.addEventListener("click", () => {
// if index is less then MCQS.length
if (index !== MCQS.length - 1) {
index++;
choice_que.forEach(removeActive => {
removeActive.classList.remove("active");
})
//question
loadData();
//result
total_correct.style.display = "block";
total_correct.innerHTML = `${correct} Out Of ${MCQS.length} Questions`;
} else {
index = 0;
//when Quiz Question Complete Display Result Section
quiz.style.display = "none";
points.innerHTML = `You Got ${correct} Out Of ${MCQS.length}`;
result.style.display = "block";
}
for (i = 0; i <= 3; i++) {
choice_que[i].classList.remove("disabled");
}
})
//what happen when 'Quit' Button Will Click
quit.addEventListener("click", () => {
start.style.display = "block";
result.style.display = "none";
});
//Start Again When 'Start Again' Button Will Clicked
startAgain.addEventListener("click", () => {
guide.style.display = "block";
result.style.display = "none";
loadData();
});
});