-
Notifications
You must be signed in to change notification settings - Fork 0
/
Color_Fliper_1.html
52 lines (49 loc) · 1.66 KB
/
Color_Fliper_1.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin:0px;
padding:0px;
box-sizing: border-box;
}
.container{
width:100vw;
height:100vh;
display:flex;
flex-direction:column;
align-items: center;
padding-top: 250px;
}
#btn{
width:70px;
height:25px;
border-radius: 6px;
}
</style>
</head>
<body>
<div class="container">
<h1>Background-color:<span class="color" id="dai">#f5102</span></h1>
<button id="btn">Click</button>
</div>
</body>
<script type="text/javascript">
const colors = ["green" ,"red","rgba(133,122,200)", "#f15025"];
const color = document.getElementById('dai');
const click = document.getElementById('btn');
click.addEventListener('click',() => {
let rendom = rendome_number();
console.log(colors[rendom]);
color.innerHTML = colors[rendom];
document.body.style.backgroundColor = colors[rendom];
});
const rendome_number = function(){
return Math.floor(Math.random()*colors.length);
}
// console.log(Math.random(Math.floor()*5));
</script>
</html>