-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
93 lines (88 loc) · 3.46 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
const questionContainer = document.querySelector(".option-container");
for (let i = 1; i <= 120; i++) {
const option = document.createElement("div");
questionContainer.append(option);
option.className = "option";
const questionNumberContainer = document.createElement("div");
questionNumberContainer.className = "question-number-container";
questionNumberContainer.innerText = i;
const questionOptionContainer = document.createElement("div");
questionOptionContainer.className = "question-option-container";
option.append(questionNumberContainer, questionOptionContainer);
const opt = ["A", "B", "C", "D"];
opt.forEach((op) => {
const questionOptionInside = document.createElement("div");
questionOptionInside.className = "question-option-inside";
questionOptionContainer.append(questionOptionInside);
questionOptionInside.setAttribute("selected", "false");
questionOptionInside.innerText = op;
questionOptionInside.addEventListener("click", (e) => {
const children = questionOptionInside.parentElement.querySelector(
".question-option-inside[selected='true']"
);
if (children && e.target != children) {
children.setAttribute("selected", "false");
}
questionOptionInside.setAttribute(
"selected",
questionOptionInside.getAttribute("selected") === "true"
? "false"
: "true"
);
});
});
}
const clear = document.querySelector(".clear-btn");
clear.addEventListener("click", (e) => {
window.scrollTo({
top: 0,
behavior: "smooth",
});
document.querySelector(".result-container .result").innerText = "?/120";
const qo = document.querySelectorAll(".question-option-inside");
qo.forEach((q) => {
q.setAttribute("selected", "false");
});
});
const result = document.querySelector(".result-btn");
result.addEventListener("click", (e) => {
let mark = 0;
const ansKey =
document
.querySelector(".part-option-container div[selected='true']")
.innerText.trim() === "A"
? "DBAADAABADBDBCDCCBBABBDCCACDBADDDCABCADDBABABCBABAABCADBABBCADBDACBBCDCDABBBDCACABCDBBDCADCDCACACBDBDDABCBBBABCBBAADCBDA"
: "ABCADBABBCADBDACBBCDCDABBBDCACABCDBBDCADCDCACACBDBDDABCBBBABCBBAADCBDADBAADAABADBDBCDCCBBABBDCCACDBADDDCABCADDBABABCBABA";
const selectedAnsContainers = document.querySelectorAll(
".question-option-container"
);
selectedAnsContainers.forEach((selectedAnsContainer, index) => {
const selectedOptions = Array.from(selectedAnsContainer.children);
selectedOptions.forEach((o) => {
if (o.getAttribute("selected") === "true") {
if (o.innerText.trim() == ansKey[index]) {
mark = mark + 1;
}
}
});
});
document.querySelector(".result-container .result").innerText = `${mark}/120`;
document.querySelector(".result-wrapper").setAttribute("display", "true");
});
const partOptions = Array.from(
document.querySelectorAll(".part-option-container div")
);
partOptions.forEach((option) => {
option.addEventListener("click", (e) => {
partOptions.forEach((o) => {
o.setAttribute("selected", "false");
});
option.setAttribute(
"selected",
option.getAttribute("selected") === "true" ? "false" : "true"
);
});
});
document.querySelector(".result-close-btn").addEventListener("click", (e) => {
document.querySelector(".result-wrapper").setAttribute("display", "false");
});