Skip to content

Commit efed78b

Browse files
committed
random color generator
1 parent 3634152 commit efed78b

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

ColorGames/Ruhi14/index.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Random Color Generator</title>
8+
<link rel="stylesheet" href="style.css">
9+
</head>
10+
11+
<body>
12+
<div class="container">
13+
<div class="color-box" id="colorBox"></div>
14+
<button onclick="changeColor()">Generate Random Color</button>
15+
</div>
16+
17+
<script src="script.js"></script>
18+
</body>
19+
20+
</html>

ColorGames/Ruhi14/script.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function getRandomColor() {
2+
const letters = '0123456789ABCDEF';
3+
let color = '#';
4+
for (let i = 0; i < 6; i++) {
5+
color += letters[Math.floor(Math.random() * 16)];
6+
}
7+
return color;
8+
}
9+
10+
function changeColor() {
11+
const colorBox = document.getElementById('colorBox');
12+
const randomColor = getRandomColor();
13+
colorBox.style.backgroundColor = randomColor;
14+
colorBox.textContent = `Color: ${randomColor}`;
15+
}
16+

ColorGames/Ruhi14/style.css

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
body {
2+
display: flex;
3+
justify-content: center;
4+
align-items: center;
5+
height: 100vh;
6+
margin: 0;
7+
}
8+
9+
.container {
10+
text-align: center;
11+
}
12+
13+
.color-box {
14+
width: 200px;
15+
height: 200px;
16+
margin: 20px auto;
17+
border: 2px solid black;
18+
}
19+
20+
button {
21+
font-size: 18px;
22+
padding: 10px 20px;
23+
cursor: pointer;
24+
}

0 commit comments

Comments
 (0)