Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add Random Color Generator mini project#56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Aditya-githubbb wants to merge1 commit intotajulafreen:main
base:main
Choose a base branch
Loading
fromAditya-githubbb:git-checkout--b-add-random-color-generator
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletionsrandom-color-generator/index.html
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Random Color Generator</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<div id="colorCode">#FFFFFF</div>
<button id="btn">Generate Color</button>
</div>

<script src="script.js"></script>
</body>
</html>
18 changes: 18 additions & 0 deletionsrandom-color-generator/script.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
const colorCode = document.getElementById('colorCode');
const btn = document.getElementById('btn');

function getRandomColor() {
const hex = Math.floor(Math.random() * 0xffffff)
.toString(16)
.padStart(6, '0');
return `#${hex}`;
}

function setColor() {
const color = getRandomColor();
document.body.style.backgroundColor = color;
colorCode.textContent = color;
}

btn.addEventListener('click', setColor);
window.addEventListener('load', setColor);
36 changes: 36 additions & 0 deletionsrandom-color-generator/styles.css
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
* {
box-sizing: border-box;
}
body, html {
margin: 0;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
font-family: sans-serif;
background-color: #ffffff;
}
.container {
text-align: center;
padding: 2rem;
border: 2px solid #ccc;
border-radius: 12px;
background-color: white;
}
#colorCode {
font-size: 2rem;
margin-bottom: 1rem;
font-weight: bold;
}
#btn {
padding: 10px 20px;
font-size: 1rem;
border: none;
background-color: #0077ff;
color: white;
border-radius: 6px;
cursor: pointer;
}
#btn:hover {
background-color: #005fcc;
}

[8]ページ先頭

©2009-2025 Movatter.jp