-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
35 lines (28 loc) · 836 Bytes
/
app.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','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]
//check answers
userAnswers.forEach((answer, index) => {
if(answer === correctAnswers[index]){
score += 25;
}
})
// show result on page
scrollTo(0,0);
result.classList.remove('d-none');
let output = 0;
const timer = setInterval(() => {
result.querySelector('span').textContent = `${output}%`;
if(output === score){
clearInterval(timer);
}else{
output ++;
}
}, 10);
})
//window object (global object)
c