Skip to content

Commit 83fa4f1

Browse files
committed
Background Color Changer
1 parent c9a91fe commit 83fa4f1

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const btn = document.getElementById("btn");
2+
let hex = document.getElementById("hexCode");
3+
4+
function randomColor() {
5+
let letters = "0123456789ABCDEF";
6+
let color = "#";
7+
for (let i = 0; i < 6; i++) {
8+
color += letters[Math.floor(Math.random() * 16)];
9+
}
10+
return color;
11+
}
12+
13+
btn.addEventListener("click", () => {
14+
document.body.style.backgroundColor = randomColor();
15+
hex.innerHTML = randomColor();
16+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<html lang="en">
2+
<head>
3+
<meta charset="UTF-8" />
4+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Random Background Color Changer</title>
7+
<link rel="stylesheet" href="style.css" />
8+
</head>
9+
<body>
10+
<button id="btn">Click Me</button>
11+
<h2 id="hexCode">#8a2be2</h2>
12+
13+
<script src="app.js"></script>
14+
</body>
15+
</html>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
body {
2+
background: blueviolet;
3+
min-height: 90vh;
4+
display: flex;
5+
flex-direction: column;
6+
justify-content: center;
7+
align-items: center;
8+
transition: 0.3s cubic-bezier(0.215, 0.61, 0.355, 1);
9+
}
10+
11+
h2 {
12+
color: #fff;
13+
font-weight: 200;
14+
}
15+
16+
button {
17+
padding: 15px;
18+
background: transparent;
19+
border: 2px solid white;
20+
color: #fff;
21+
transition: 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
22+
}
23+
24+
button:hover {
25+
background: #fff;
26+
color: #000;
27+
cursor: pointer;
28+
}
29+
30+
button:active {
31+
padding: 5px;
32+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@ Click on the Title to open the Respective Folder
5050
# 14 [Heart](https://github.com/BhalliBhai/HTML-CSS-JavaScript/tree/main/14.%20Heart)
5151
<img src="https://github.com/BhalliBhai/HTML-CSS-JavaScript/blob/main/SnapShots/Heart.png" alt="Heart">
5252

53-
# 15 []()
53+
# 15 [Background Color Changer]()
5454
<img src="" alt="">

0 commit comments

Comments
 (0)