Working on 1. Color Flipper
parent
e1e6fe1afe
commit
6bafaa3d5f
|
@ -1 +1,14 @@
|
||||||
const colors = ["green", "red", "rgba(133,122,200)", "#f15025"];
|
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 = getRandomNumber();
|
||||||
|
document.body.style.backgroundColor = colors[randomNumber];
|
||||||
|
color.textContent = colors[randomNumber];
|
||||||
|
})
|
||||||
|
|
||||||
|
function getRandomNumber() {
|
||||||
|
return Math.floor(Math.random()*4);
|
||||||
|
}
|
|
@ -9,7 +9,22 @@
|
||||||
<link rel="stylesheet" href="styles.css" />
|
<link rel="stylesheet" href="styles.css" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<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 -->
|
<!-- javascript -->
|
||||||
<script src="app.js"></script>
|
<script src="app.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
# README
|
# README
|
||||||
|
|
||||||
This is a practice repo following https://github.com/john-smilga/javascript-basic-projects
|
This is a practice repo following https://github.com/john-smilga/javascript-basic-projects, which is part of [40 JavaScript Projects for Beginners – Easy Ideas to Get Started Coding JS](https://www.freecodecamp.org/news/javascript-projects-for-beginners/#how-to-create-a-color-flipper)
|
Loading…
Reference in New Issue