- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
Latest commit
30 lines (25 loc) · 677 Bytes
/
Copy pathscript.js
File metadata and controls
30 lines (25 loc) · 677 Bytes
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
constdarkColorsArr=[
'#2C3E50',
'#34495E',
'#2C2C2C',
'#616A6B',
'#4A235A',
'#2F4F4F',
'#0E4B5A',
'#36454F',
'#2C3E50',
'#800020',
];
functiongetRandomIndex(){
constrandomIndex=Math.floor(darkColorsArr.length*Math.random());
returnrandomIndex;
}
constbody=document.querySelector('body');
constbgHexCodeSpanElement=document.querySelector('#bg-hex-code');
functionchangeBackgroundColor(){
constcolor=darkColorsArr[getRandomIndex()];
bgHexCodeSpanElement.innerText=color;
body.style.backgroundColor=color;
}
constbtn=document.querySelector('#btn');
btn.onclick=changeBackgroundColor;