-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfifty-shades-of-cold.js
35 lines (31 loc) · 1.1 KB
/
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
34
35
import { colors } from "./fifty-shades-of-cold.data.js"
const coldShades = ["aqua", "blue", "turquoise", "green", "cyan", "navy", "purple"]
export const generateClasses = () => {
let style = document.createElement('style')
colors.forEach((color) => {
if (style.styleSheet) {
// This is required for IE8 and below.
style.styleSheet.cssText = `.${color} {background : ${color};}`;
} else {
style.appendChild(document.createTextNode(`.${color} {background : ${color};}`));
}
})
document.head.appendChild(style)
}
export const generateColdShades = () => {
colors.forEach((color) => {
if(coldShades.some((cold) => RegExp(`${cold}`).test(color))) {
let div = document.createElement('div')
div.className = color
div.innerHTML = color
document.body.appendChild(div)
}
})
}
export const choseShade = (shade) => {
let divs = document.querySelectorAll('div')
for (let index = 0; index < divs.length; index++) {
const div = divs[index]
div.className = shade
}
}