-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
94 lines (65 loc) · 2.25 KB
/
index.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<style>
.box{width:100px;height:100px;
border:1px solid black;
}
</style>
<div style='display:flex'>
<div id='1' class='box'></div>
<div id='2' class='box'></div>
<div id='3' class='box'></div>
<div id='4' class='box'></div>
</div>
<div style='display:flex'>
<div id='5' class='box'></div>
<div id='6' class='box'></div>
<div id='7' class='box'></div>
<div id='8' class='box'></div>
</div>
<div style='display:flex'>
<div id='9' class='box'></div>
<div id='10' class='box'></div>
<div id='11' class='box'></div>
<div id='12' class='box'></div>
</div>
<div style='display:flex'>
<div id= '13' class='box'></div>
<div id= '14' class='box'></div>
<div id= '15' class='box'></div>
<div id= '16' class='box'></div>
</div>
<script>
molePosition=0
let boxes = document.getElementsByClassName('box')
for(let i=0;i<boxes.length;i++){
boxes[i].onclick=()=>clickedCell(i)
}
setInterval(popUpMole,1000)
function popUpMole(){
//Don't do this the very first time (when molePosition ==0 - becuase there is no position 0)
if (molePosition>0){document.getElementById(molePosition).style.backgroundColor='white'}
molePosition = Math.floor(Math.random() * 16) +1
document.getElementById(molePosition).style.backgroundColor='brown'
}
function clickedCell(i){
console.log(i)
if (i==molePosition){
//it's a hit
document.getElementById(molePosition).style.backgroundColor='red'
}
else{
//it's a miss (we clicked the wrong cell)
document.getElementById(i).style.backgroundColor='blue'
}
}
</script>
</body>
</html>