-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
35 lines (27 loc) · 1002 Bytes
/
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
const correctAnswers = ['B', 'B', 'A', 'B', 'B', 'B', 'B', 'B'];
const form = document.querySelector('.quiz-form');
const result = document.querySelector('.result');
form.addEventListener('submit', e => {
e.preventDefault();
let score = 0;
const userAnswers = [form.Q1.value, form.Q2.value, form.Q3.value, form.Q4.value, form.Q5.value, form.Q6.value, form.Q7.value, form.Q8.value]
//Answers Check(Cummulative)
userAnswers.forEach((answer, index) => {
if (answer === correctAnswers[index]) {
score += (100/8)
}
});
//Result Display and Automatic scroll up when hitting submit button
//console.log(score);
scrollTo(0, 0);
result.classList.remove('d-none');
let output = 0;
const timer = setInterval(() => {
result.querySelector('span').textContent = `${output>score?score:output}%`;
if (output >= score) {
clearInterval(timer);
} else {
output++;
}
},50)
});