-
Notifications
You must be signed in to change notification settings - Fork 0
/
fifty-shades-of-cold.js
33 lines (28 loc) · 1001 Bytes
/
fifty-shades-of-cold.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
import { colors } from "./fifty-shades-of-cold.data.js"
function generateClasses() {
const head = document.head
const style = document.createElement("style")
colors.forEach((color) => {
style.innerHTML += `.${color} {\n background: ${color};\n }\n\n`
})
head.appendChild(style)
}
function generateColdShades() {
const coldKeywords = ["aqua", "blue", "turquoise", "green", "cyan", "navy", "purple"]
const body = document.body
colors.forEach((color) => {
if (coldKeywords.some(keyword => color.includes(keyword))) {
const div = document.createElement("div");
div.classList.add(color)
div.innerHTML = color
div.addEventListener("click", () => choseShade(color))
body.appendChild(div)
}
})
}
function choseShade(shade) {
document.querySelectorAll("div").forEach((div) => {
div.className = shade
})
}
export { generateClasses, generateColdShades, choseShade }