-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.js
95 lines (84 loc) · 2.15 KB
/
1.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
var questionQuiz = [
{ question: 'Bác Hồ sinh năm bao nhiêu ?',
answer_a: '1900',
answer_b: '1911',
answer_c: '1890',
answer_d: '1891',
correct: 'c'
},
{ question: '1 + 1 = ?',
answer_a: '4',
answer_b: '2',
answer_c: '5',
answer_d: '6',
correct: 'b'
},
{ question: '2 + 2 = ?',
answer_a: '4',
answer_b: '2',
answer_c: '5',
answer_d: '6',
correct: 'a'
},
{ question: '2 * 3 = ?',
answer_a: '4',
answer_b: '2',
answer_c: '5',
answer_d: '6',
correct: 'd'
}
]
const questionNumber = document.getElementById('question');
const answer_a = document.getElementById('answer_a');
const answer_b = document.getElementById('answer_b');
const answer_c = document.getElementById('answer_c');
const answer_d = document.getElementById('answer_d');
const submit = document.getElementById('btn');
const answerEls = document.querySelectorAll('.contact');
const end = document.getElementById('end');
const screen = document.querySelector('.card');
let currentQuiz = 0;
let score = 0;
loadQuestion();
function loadQuestion(){
let numberQuestion = questionQuiz[currentQuiz];
questionNumber.innerText = numberQuestion.question;
answer_a.innerText = numberQuestion.answer_a;
answer_b.innerText = numberQuestion.answer_b;
answer_c.innerText = numberQuestion.answer_c;
answer_d.innerText = numberQuestion.answer_d;
}
function getAnswer(){
let answer = undefined;
answerEls.forEach((answerEl) => {
if(answerEl.checked){
answer = answerEl.id;
}
});
return answer;
}
function deleteAnswer(){
answerEls.forEach((answerEl) => {
if(answerEl.checked){
answerEl.checked = false;
}
});
}
submit.addEventListener('click', () => {
const answer = getAnswer();
if(answer){
if(answer === questionQuiz[currentQuiz].correct){
score++;
}
currentQuiz++;
if(currentQuiz < questionQuiz.length){
deleteAnswer();
loadQuestion();
}
else {
screen.classList.add('active');
end.classList.add('active');
end.innerText = `You finished Quiz Question. Score is ${score}`;
}
}
});