-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.html
51 lines (46 loc) · 1.59 KB
/
game.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Number Guessing Game</title>
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="../styles.css" />
</head>
<body style="background-color: #212121; color: #fff">
<nav>
<a href="/" aria-current="page">Home</a>
<a target="_blank" href="https://www.youtube.com/@chaiaurcode"
>Youtube channel</a
>
</nav>
<h1>Start should change the Background color every second</h1>
<button id="start">Start</button>
<button id="stop">Stop</button>
<script>
const rendomcolour=function()
{
const hex="0123456789ABCDEF";
let clolor="#";
for (let index = 0; index < 6; index++) {
clolor+=hex[Math.floor(Math.random()*16)];
}return clolor;
}
let change;
function StartChangingColor(){
clearInterval(change);//multiple click par multiple interval na chale
change=setInterval(changecolor,1000);
function changecolor()
{
document.body.style.backgroundColor=rendomcolour();
}
};
function StopChangingColor(){
clearInterval(change);
}
document.getElementById('start').addEventListener('click',StartChangingColor);
document.getElementById('stop').addEventListener('click',StopChangingColor);
</script>
</body>
</html>