-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
56 lines (43 loc) · 772 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
;(function() {
'use strict'
//
// Variables
//
const app = document.querySelector('#app')
const data = {
timer: 60
}
let count = data.timer
//
// Methods
//
const template = _ => {
if (count === 0) {
return '<p>⏰</p><button id="restart">Restart Timer</button>'
}
return `<p>${count}</p>`
}
const render = _ => {
app.innerHTML = template()
}
const startTimer = _ => {
const countdown = setInterval(function() {
render()
count--
if (count < 0) {
clearInterval(countdown)
}
}, 1000)
}
const restartTimer = _ => {
if (event.target.id === 'restart') {
count = data.timer
startTimer()
}
}
//
// Inits & Event Listeners
//
startTimer()
document.addEventListener('click', restartTimer, false)
})()