-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
37 lines (31 loc) · 1.2 KB
/
script.js
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
32
33
34
35
36
37
const containerEl = document.querySelector(".container");
for(let i = 0; i < 30; i++) {
const colorContainerEl = document.createElement("div");
colorContainerEl.classList.add("color_container");
containerEl.appendChild(colorContainerEl);
}
const color_container = containerEl.querySelectorAll(".color_container");
colorGenerate ();
function colorGenerate () {
color_container.forEach ((color_container) => {
const newColor = randomNumberGenerate();
color_container.style.backgroundColor = "#" + newColor;
color_container.innerText = "#" + newColor;
});
}
function randomNumberGenerate () {
const colorCodeTg = "0123456789abcdef";
const colorCodeLength = 6;
let colorTg = "";
for(let i = 0; i < colorCodeLength; i++) {
const randomNumber = Math.floor(Math.random() * colorCodeTg.length);
colorTg += colorCodeTg.substring(randomNumber, randomNumber + 1);
}
return colorTg;
}
color_container.forEach ((colorContainer) => {
colorContainer.addEventListener("click", () => {
navigator.clipboard.writeText(colorContainer.innerText);
alert(`${colorContainer.innerText} Copied`);
})
});