-
Notifications
You must be signed in to change notification settings - Fork 0
/
Statistics.js
41 lines (36 loc) · 973 Bytes
/
Statistics.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
class Statistics {
constructor() {
this.correct = 0
this.total = 0
this.successRatio = 0
this.updateHtml()
}
checkQuestions(questions) {
this.correct = 0
this.total = questions.length
questions.forEach(question => {
if (question.isCorrect) {
this.correct++
}
})
this.updateSuccessRatio()
}
addFailure() {
this.total++
this.updateSuccessRatio()
}
addSuccess() {
this.correct++
this.total++
this.updateSuccessRatio()
}
updateSuccessRatio() {
this.successRatio = Math.ceil(this.correct / this.total * 100)
this.updateHtml()
}
updateHtml() {
document.getElementById('correct').innerHTML = this.correct
document.getElementById('total').innerHTML = this.total
document.getElementById('successRatio').innerHTML = this.successRatio
}
}