-
Notifications
You must be signed in to change notification settings - Fork 2
/
dom-hexa-color.js
62 lines (53 loc) · 1.58 KB
/
dom-hexa-color.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Creating
// creatElement
const body = document.body
const colorWrapper = document.createElement('div')
body.appendChild(colorWrapper)
colorWrapper.style.display = 'flex'
colorWrapper.style.flexWrap = 'wrap'
colorWrapper.style.width = '75%'
colorWrapper.style.margin = 'auto'
// const title = document.createElement('h1')
// title.textContent = 'DOM is great'
// title.style.color = 'green'
// body.appendChild(title)
// const firstPara = document.createElement('p')
// firstPara.textContent =
// 'JavaScript is awesome and you should learn it. You will be able make every website very dynamic'
// body.appendChild(firstPara)
// for (let i = 0; i < 1000; i++) {
// let number = document.createElement('h1')
// number.style.textAlign = 'center'
// number.style.fontSize = '72px'
// if (i % 2 === 0) {
// number.style.color = 'green'
// } else {
// number.style.color = 'red'
// }
// number.textContent = i
// body.appendChild(number)
// }
// #012ef3
const genHexaColor = () => {
const str = '0123456789abcdef'
let hexa = ''
for (let i = 0; i < 6; i++) {
let index = Math.floor(Math.random() * str.length)
hexa += str[index]
}
return '#' + hexa
}
for (let i = 0; i < 10000; i++) {
let div = document.createElement('div')
let backgroundColor = genHexaColor()
div.textContent = backgroundColor
div.style.width = '150px'
div.style.height = '150px'
div.style.margin = '10px'
div.style.borderRadius = '8px'
div.style.textAlign = 'center'
div.style.lineHeight = '150px'
div.style.backgroundColor = backgroundColor
colorWrapper.appendChild(div)
}
//