-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
117 lines (99 loc) · 2.66 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
const quizData = [
{
question: `What is part of a database that holds only one type of information?
`,
a: "Report",
b: "Field",
c: "Record",
d: "File",
correct: "b"
},
{
question: `
'OS' computer abbreviation usually means ?`,
a: `Order of Significance`,
b: `Open Software`,
c: `Operating System`,
d: `Optical Sensor`,
correct: "c"
},
{
question: `'.MOV' extension refers usually to what kind of file?`,
a: `Image file`,
b: `Animation/movie file`,
c: `Audio file`,
d: `MS Office document`,
correct: "b"
},
{
question: `The members of the Rajya Sabha are elected by`,
a: `
the people`,
b: `
Lok Sabha`,
c: `elected members of the legislative assembly`,
d: `elected members of the legislative council`,
correct: "c"
},
{
question: `The power to decide an election petition is vested in the`,
a: `Parliament`,
b: `Supreme Court`,
c: `High courts`,
d: `Election Commission`,
correct: "c"
},
];
const questionEl = document.getElementById("question");
const b_text = document.getElementById("b_text");
const c_text = document.getElementById("c_text");
const d_text = document.getElementById("d_text");
const a_text = document.getElementById("a_text");
const btn = document.getElementById("submit");
const quiz = document.getElementById("quiz");
const answerEl = document.querySelectorAll(".answer");
let currentQuiz = 0;
// let answer=undefined;
let score = 0;
function loadquiz() {
deselectAns();
const currentQuizData = quizData[currentQuiz];
questionEl.innerHTML = `${currentQuiz + 1}. ` + currentQuizData.question;
a_text.innerHTML = currentQuizData.a;
b_text.innerHTML = currentQuizData.b;
c_text.innerHTML = currentQuizData.c;
d_text.innerHTML = currentQuizData.d;
}
btn.addEventListener("click", () => {
const answer = getSelected();
console.log(answer);
if (answer) {
if (answer === quizData[currentQuiz].correct) {
score++;
}
currentQuiz++;
if (currentQuiz < quizData.length) {
loadquiz();
} else {
quiz.innerHTML = `<h2>your Score is ${score} out of ${quizData.length}</h2>
<button onClick="location.reload()">Reload Quiz</button>
`;
}
}
console.log(score);
});
loadquiz();
function getSelected() {
let answer = undefined;
answerEl.forEach((answerEl) => {
if (answerEl.checked) {
answer = answerEl.id;
}
});
return answer;
}
function deselectAns() {
answerEl.forEach((answerEl) => {
answerEl.checked = false;
});
}