-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
37 lines (33 loc) · 932 Bytes
/
index.html
File metadata and controls
37 lines (33 loc) · 932 Bytes
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
<!DOCTYPE html>
<html lang="uk">
<head>
<meta charset="UTF-8">
<title>Світлофор</title>
<style>
.light {
width: 50px;
height: 50px;
margin: 10px;
border-radius: 50%;
background-color: gray;
}
</style>
</head>
<body>
<h2>Світлофор</h2>
<div id="red" class="light"></div>
<div id="yellow" class="light"></div>
<div id="green" class="light"></div>
<br>
<button onclick="changeLight()">Перемкнути</button>
<script>
let current = 0;
const lights = ["red", "yellow", "green"];
function changeLight() {
document.getElementById(lights[current]).style.backgroundColor = "gray";
current = (current + 1) % 3;
document.getElementById(lights[current]).style.backgroundColor = lights[current];
}
</script>
</body>
</html>