-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
30 lines (26 loc) · 960 Bytes
/
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
const paletteContainer = document.getElementById('paletteContainer');
const colorValues = ['1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'];
const paletteSize = 5;
const createPalette = () => {
for (let i = 0; i < paletteSize; i++) {
const paletteElement = document.createElement('div');
paletteElement.classList.add('paletteItem');
paletteContainer.appendChild(paletteElement);
}
updatePalette();
}
const colorize = (element) => {
let color = '#';
for (let i = 0; i < 6; i++) {
const randomElement = colorValues[Math.floor(Math.random() * colorValues.length)];
color += randomElement;
};
element.style.backgroundColor = color;
element.innerHTML = `<span class='colorHex'>${color}</span>`;
}
const updatePalette = () => {
for (let i = 0; i < paletteContainer.children.length; i++) {
colorize(paletteContainer.children[i])
}
}
createPalette();