-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpractise.html
More file actions
41 lines (37 loc) · 1.08 KB
/
practise.html
File metadata and controls
41 lines (37 loc) · 1.08 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
<!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>
<button id="btn">click me</button>
<h1 id="heading"></h1>
<script>
const hex = [1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"];
window.onload = function () {
document.getElementById("btn").addEventListener("click", changeColor);
};
function displayHex(hexValue) {
document.getElementById("heading").innerHTML = hexValue;
}
function randomcolor() {
let hexa = "#";
for (let i = 0; i < 6; i++) {
hexa += hex[getRandomNumber()];
}
return hexa;
}
function getRandomNumber() {
return Math.floor(Math.random() * hex.length);
}
function changeColor() {
color = randomcolor();
document.body.style.backgroundColor = color;
displayHex(color);
}
</script>
</body>
</html>