-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
38 lines (34 loc) · 1.04 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Guess the Color</title>
<style>
button{
background-color: transparent;
padding: 20px;
border: 1px solid;
font-size: 2rem;
}
button:hover{
background-color: antiquewhite;
}
</style>
</head>
<body>
<button>Click me!</button>
<script>
const htmlBody = document.querySelector('body');
const randomClickFunction = function(){
const colors = ["yellow", "blue", "green", "black", "grey", "white", "red", "purple", "orange"];
const randomIndex = Math.floor(Math.random() * colors.length);
const randomColor = colors[randomIndex];
htmlBody.style.backgroundColor = randomColor;
console.log ('Color set to ' + randomColor);
}
randomClickFunction()
htmlBody.onclick = randomClickFunction;
</script>
</body>
</html>