-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
143 lines (94 loc) · 3.38 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
let question_count = 0
let count = 0
let correct
const sectionQ = document.querySelector('.quiz')
const asking = document.querySelector('.asking')
const answera = document.querySelector('.a')
const answerb = document.querySelector('.b')
const answerc = document.querySelector('.c')
const answerd = document.querySelector('.d')
const next = document.querySelector('.next')
const score = document.querySelector('.score')
const expo = document.querySelector('.expo')
const start = document.querySelector('.start')
start.addEventListener('click', startQuiz)
function listeners() {
answera.onclick = () => {reveal(answera)}
answerb.onclick = () => {reveal(answerb)}
answerc.onclick = () => {reveal(answerc)}
answerd.onclick = () => {reveal(answerd)}
}
function reveal(selected) {
answera.onclick = null
answerb.onclick = null
answerc.onclick = null
answerd.onclick = null
resetAnim(expo) ; resetAnim(next)
expo.classList.remove('hidden')
next.classList.remove('hidden')
next.addEventListener('click', nextQuestion)
answera.classList.add('selected')
answerb.classList.add('selected')
answerc.classList.add('selected')
answerd.classList.add('selected')
document.querySelectorAll('.alternative').forEach(indice => {
if (indice.textContent===correct) {indice.classList.add('correct')}
} )
if (selected.textContent===correct) {count++} else {console.log(selected.textContent, correct)}
if (question_count==10) {
next.classList.add('hidden')
next.removeEventListener('click', nextQuestion)
fscore()
sectionQ.style.height = 'fit-content'
}
}
function startQuiz() {
start.removeEventListener('click', startQuiz)
start.classList.add('hidden')
answera.classList.remove('hidden')
answerb.classList.remove('hidden')
answerc.classList.remove('hidden')
answerd.classList.remove('hidden')
sectionQ.style.height = '94vh'
nextQuestion()
}
function nextQuestion() {
expo.classList.add('hidden')
answera.classList.remove('selected', 'correct')
answerb.classList.remove('selected', 'correct')
answerc.classList.remove('selected', 'correct')
answerd.classList.remove('selected', 'correct')
next.classList.add('hidden')
next.removeEventListener('click', nextQuestion)
document.querySelectorAll('.alternative').forEach(indice => resetAnim(indice, question_count))
asking.innerHTML = questions[question_count].question
expo.innerHTML = questions[question_count].expo
correct = questions[question_count].correct
let sorted = questions[question_count].alternatives.sort( () => {
return Math.round(Math.random()*-1)
} )
answera.innerHTML = sorted[0]
answerb.innerHTML = sorted[1]
answerc.innerHTML = sorted[2]
answerd.innerHTML = sorted[3]
question_count++
listeners()
}
function fscore() {
const performance = (count*100)/10
score.innerHTML = 'você acertou '+count+'/10 perguntas!<br>seu desempenho é: '+performance+'%'
if (performance < 39)
{ score.classList.add('selected')
score.style.border = '2px solid white' }
else if (performance >= 40 && performance <= 66) {
score.style.backgroundColor = '#FFD700'
score.style.border = '2px solid white'
score.style.color = 'black' }
else if (performance > 66) {score.classList.add('correct')}
}
function resetAnim(el, index) {
el.style.animation = "none"
el.offsetWidth
el.style.animation = ""
if (index > 0) {el.style.animationDelay="0s"}
}