-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
44 lines (27 loc) · 996 Bytes
/
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
let span = document.querySelector("span");
let body = document.querySelector("body");
// For the color picker;
const colorPicker = document.getElementById("colorPicker");
colorPicker.addEventListener("input", ()=>{
// setting background color what user selected;
document.body.style.backgroundColor = colorPicker.value;
// updating span text;
span.innerText = colorPicker.value;
})
// for the random hex code generation;
// setting the initial value, what has been set
body.style.backgroundColor = span.innerText;
function generate() {
let randomColor = "";
// characters used in hex codes;
let chars = "0123456789abcdef";
for(i = 0; i < 6; i++)
{
randomColor += chars[Math.floor(Math.random() * 16)];
}
span.innerText = "#" + randomColor;
// setting background color what was randomly generated;
body.style.backgroundColor = span.innerText;
// updating color picker value;
colorPicker.value = span.innerText;
}