-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
44 lines (28 loc) · 824 Bytes
/
script.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
function randomInteger( min, max ) {
return Math.floor( Math.random() * (max-min) + min );
}
function generateHexColor() {
let hexCode = '#';
for (let i = 0; i < 6; i++){
hexCode += hexCharacters[randomInteger(0, hexCharacters.length)]
}
return hexCode;
}
function updateBgColor( color ) {
document.body.style.backgroundColor = color;
}
function updateText( color ) {
span.textContent = color;
}
function newColor() {
const color = generateHexColor();
updateBgColor( color );
updateText(color);
}
const span = document.querySelector('span');
const button = document.querySelector('button');
button.addEventListener('click', newColor);
const hexCharacters = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F'];
window.onload = () => {
newColor();
}