Skip to content

Commit 03fa62c

Browse files
committed
done
1 parent 65764d8 commit 03fa62c

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed
Loading
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+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
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+
<body>
11+
<header>
12+
<h1>Random Color Generator</h1>
13+
</header>
14+
<section>
15+
<div class="container">
16+
</div>
17+
</section>
18+
<script src="script.js"></script>
19+
</body>
20+
</html>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Convert the id into a element
2+
const containerEl = document.querySelector(".container")
3+
4+
// Using FOR LOOP
5+
// in for loop index start at 0 and you can replace array.length with the number of elements you want
6+
for (let index = 0; index < 30; index++) {
7+
// We have to create an element for the div
8+
const colorContainerEl = document.createElement("div")
9+
// Then, to add a class we can use the classList property and add method
10+
colorContainerEl.classList.add("color-container")
11+
//Next, we need to append this new element inside this container... so write container element.append
12+
containerEl.appendChild(colorContainerEl)
13+
}
14+
const colorContainerEls = document.querySelectorAll(".color-container")
15+
16+
generateColors();
17+
18+
function generateColors(){
19+
colorContainerEls.forEach((colorContainerEl) => {
20+
const newColorCode = randomColor();
21+
colorContainerEl.style.backgroundColor = "#" + newColorCode;
22+
colorContainerEl.innerText = "#" + newColorCode;
23+
});
24+
}
25+
26+
//Back in HTML remove the boxes we created with the "div"
27+
28+
//Create a color codes using a function
29+
30+
function randomColor() {
31+
const chars = "0123456789abcdef"
32+
const colorCodeLength = 6;
33+
let colorCode = ""; //start with empty and then we use for loop again, replace array.length now with the colorCodeLength
34+
for (let index = 0; index < colorCodeLength; index++) {
35+
// want to create a variable from 0-15 from the chars
36+
const randomNumber = Math.floor(Math.random()*
37+
chars.length)
38+
colorCode += chars.substring(randomNumber,randomNumber+1)
39+
40+
}
41+
return colorCode;
42+
}
43+
44+
45+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
*{
2+
margin: 0;
3+
padding: 0;
4+
box-sizing: border-box;
5+
font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
6+
}
7+
body{
8+
background-image: url(felix-dubois-robert-CuEvrPd3NYc-unsplash.jpg);
9+
background-repeat: no-repeat;
10+
background-size: cover;
11+
}
12+
h1 {
13+
text-align: center;
14+
color: white;
15+
text-shadow: 2px 3px 4px grey;
16+
text-decoration:underline
17+
}
18+
19+
.container {
20+
display: flex;
21+
flex-wrap: wrap;
22+
justify-content: center;
23+
}
24+
25+
.color-container {
26+
background-color: orange;
27+
width: 300px;
28+
height: 150px;
29+
color: white;
30+
margin: 5px;
31+
display: flex;
32+
justify-content: center;
33+
align-items: center;
34+
font-size: 25px;
35+
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
36+
border: solid black 2px;
37+
border-radius: 10px;
38+
}

0 commit comments

Comments
 (0)