-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
61 lines (53 loc) · 1.21 KB
/
index.html
File metadata and controls
61 lines (53 loc) · 1.21 KB
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
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JavaScript Practice</title>
<style>
body {
display: flex;
flex-wrap: wrap;
}
.box {
width: 100px;
height: 100px;
background-color: skyblue;
cursor: pointer;
transition: 0.8s;
margin: 0 8px 8px 0;
text-align: center;
line-height: 100px;
}
.win {
background: pink;
border-radius: 50%;
transform: rotate(360deg);
}
.lose {
transform: scale(0.9);
}
</style>
</head>
<body>
<script>
'use script';
const num = 10;
const winner = Math.floor(Math.random() * num); //0 - 9
for (let i = 0; i < num; i++) {
const div = document.createElement('div');
div.classList.add('box');
div.addEventListener('click', () => {
if (i === winner) {
div.textContent = '当たり!';
div.classList.add('win');
} else {
div.textContent = 'ハズレ...';
div.classList.add('lose');
}
});
document.body.appendChild(div);
}
</script>
</body>
</html>