-
Notifications
You must be signed in to change notification settings - Fork 6
/
traffic-light.html
68 lines (58 loc) · 1.18 KB
/
traffic-light.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Traffic lights</title>
<meta charset="UTF-8">
<style>
.box {
display: flex;
flex-direction: column;
width: 100vw;
margin: 35vh 0;
}
.box * {
align-self: center;
background-color: #eeeeee;
}
#light {
width: 200px;
border-radius: 50px;
color: white;
font-size: 96pt;
padding: 10px 50px;
}
.green {
background-color: green
}
#timer {
margin: 5vh;
padding: 10px;
}
</style>
</head>
<body>
<div class="box">
<div id="light"> </div>
<div id="timer"></div>
</div>
<script>
(() => {
const light = document.getElementById('light')
const start = new Date().getTime()
function turnGreen() {
light.classList.remove('red')
light.classList.add('green')
}
function showText() {
light.innerText = "GO!"
}
function updateTimer() {
document.getElementById('timer').innerText = `${Math.round((new Date().getTime() - start) / 1000)} s.`
}
setTimeout(turnGreen, 2500)
setTimeout(showText, 5000)
setInterval(updateTimer, 100)
})()
</script>
</body>
</html>