Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
13 changes: 13 additions & 0 deletions 01-color-flipper/setup/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
const colors = ["green", "red", "rgba(133,122,200)", "#f15025"];
const btn = document.getElementById("btn");
const color = document.querySelector(".color");

btn.addEventListener("click", function () {
const randomNumber = getRandom(colors.length);

color.textContent = colors[randomNumber];
document.body.style.backgroundColor = colors[randomNumber];
})

function getRandom (n) {
return Math.floor(Math.random() * n);
}
17 changes: 17 additions & 0 deletions 01-color-flipper/setup/hex.js
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
const hex = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"];
const btn = document.getElementById('btn');
const color = document.querySelector('.color');

btn.addEventListener('click', function () {
let hexColor = '#';
for (let i = 0; i < 6; i++) {
const randomNumber = getRandom(hex.length);
hexColor += hex[randomNumber];
}

color.textContent = hexColor;
document.body.style.backgroundColor = hexColor;
})

function getRandom (n) {
return Math.floor(Math.random() * n);
}
27 changes: 26 additions & 1 deletion 01-color-flipper/setup/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,32 @@
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<h1>color flipper</h1>
<nav>
<div class="nav-center">
<h4>Color Flipper</h4>
<ul class="nav-links">
<li>
<a href="index.html">simple</a>
</li>
<li>
<a href="hex.html">hex</a>
</li>
</ul>
</div>
</nav>
<main>
<div class="container">
<h2>
background color :
<span class="color">
#f1f5f8
</span>
</h2>
<button class="btn btn-hero" id="btn">
click me
</button>
</div>
</main>
<!-- javascript -->
<script src="app.js"></script>
</body>
Expand Down