-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
31 lines (26 loc) · 968 Bytes
/
script.js
File metadata and controls
31 lines (26 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const containerEl = document.querySelector(".container")
for (let index = 0; index < 32; index++) {
const colorContainerEl = document.createElement("div")
colorContainerEl.classList.add("color-container")
containerEl.appendChild(colorContainerEl);
}
const colorContainerEls = document.querySelectorAll(".color-container");
generateColors()
function generateColors(){
colorContainerEls.forEach(
(colorContainerEl)=>{
const newColorCode = randomColor()
colorContainerEl.style.backgroundColor = "#" + newColorCode;
colorContainerEl.innerText = "#" + newColorCode
});
}
function randomColor(){
const chars = "0123456789abcdef";
const colorCodeLength = 6;
let colorCode = "";
for (let index = 0; index < colorCodeLength; index++) {
const randomNum = Math.floor(Math.random()* chars.length);
colorCode += chars.substring(randomNum,randomNum + 1);
}
return colorCode;
}