-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
115 lines (94 loc) · 3.51 KB
/
main.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
var divStart = document.getElementById('start'),
divTimer = document.getElementById('timer'),
divStop = document.getElementById('stop'),
divRestart = document.getElementById('restart')
var btnStart = document.getElementById('btnStart'),
btnStop = document.getElementById('btnStop'),
btnRestart = document.getElementById('btnRestart')
var elemTime = document.getElementById('time'),
elemGo = document.getElementById('go'),
elemStopText = document.getElementById('stopText'),
elemProp = document.getElementById('prop'),
elemDiff = document.getElementById('diff')
let indikator = 0,
start = 0,
count = 0,
interval = 0,
end = 0,
time = 0,
prop = 0
/* let props = [
['Super Reaktionszeit 🎉', 'Klasse gemacht 🙌', 'Besser geht es kaum 😎'],
['Das müssen wir üben 🙄', 'Hier musst du was tun 🤐'],
['Ich bin enttäuscht 😒', 'Alles gut bei dir? 😮', 'Schämst du dich nicht? 😣']
] */
let props = [
['Great response time 🎉', 'Well done 🙌', "It couldn't be better 😎"],
['We have to practice that 🙄', 'We have to do something here 🤐'],
["I'm disappointed 😒", 'Everything ok with you? 😮', 'Are you not ashamed? 😣']
]
init()
btnStart.addEventListener('click', function () {
divStart.style.display = 'none'
divTimer.style.display = 'block'
elemGo.innerText = 3
interval = setInterval(function () {
if (count == 0) {
elemGo.innerText = 2
} else if (count == 1) {
elemGo.innerText = 1
} else if (count == 2) {
divTimer.style.display = 'none'
divStop.style.display = 'block'
elemStopText.style.color = 'black'
elemStopText.innerText = 'Go'
start = new Date().getTime()
} else if (count == 3) {
elemStopText.innerText = 'Stop'
elemStopText.style.color = ''
clearInterval(interval)
}
count++
}, 1000);
})
btnStop.addEventListener('click', function () {
divStop.style.display = 'none'
divRestart.style.display = 'block'
end = new Date().getTime()
time = Math.round(((end - start) / 1000 - indikator) * 100) / 100
prop = 100 / indikator * (time)
if (prop <= 6 && prop >= -6) {
elemProp.innerText = getRandomProp(0)
elemDiff.classList.add('text-success')
elemDiff.classList.remove('text-warning', 'text-danger')
} else if (prop <= 15 && prop >= -15) {
elemProp.innerText = getRandomProp(1)
elemDiff.classList.add('text-warning')
elemDiff.classList.remove('text-success', 'text-danger')
} else {
elemProp.innerText = getRandomProp(2)
elemDiff.classList.add('text-danger')
elemDiff.classList.remove('text-success', 'text-warning')
}
elemDiff.innerText = time.toString().includes('-') ? time : '+' + time
})
btnRestart.addEventListener('click', function () {
init()
})
function init() {
indikator = getRandomTime()
start = 0
count = 0
end = 0
time = 0
divStart.style.display = 'block'
divStop.style.display = 'none'
divRestart.style.display = 'none'
elemTime.innerText = indikator
}
function getRandomTime() {
return Math.floor(Math.random() * (10 - 3)) + 3
}
function getRandomProp(row) {
return props[row][Math.floor((Math.random() * props[row].length))]
}