-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
46 lines (32 loc) · 1.19 KB
/
main.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
// alert("hello world!");
const containerEl =document.querySelector('.container');
// no we create For to randamly color generated from our project //
for(let i =0; i < 50; i++){
const colorContainerEl = document.createElement('div');
colorContainerEl.classList.add('color-container');
containerEl.appendChild(colorContainerEl);
}
const colorContainerEls = document.querySelectorAll('.color-container');
console.log(colorContainerEls)
// create function to generated box color;
function generateColors(){
colorContainerEls.forEach(()=>{
const newColorCode = randomColor();
// console.log(newColorCode)
colorContainerEl.style.backgroundColor = "#" + newColorCode;
})
}
generateColors();
// create function to generated color;
function randomColor(){
const chars = "0123456789abcdef";
const colorCodeLength = 6;
let colorCode ="";
for(let i = 0; i < colorCodeLength; i++){
const randomNum = Math.floor(Math.random() * chars.length);
// console.log(randomNumber);
colorCode += chars.substring(randomNum, randomNum+1);
}
return colorCode;
}
randomColor();