-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
26 lines (19 loc) · 784 Bytes
/
script.js
File metadata and controls
26 lines (19 loc) · 784 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
const hexNumbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F'];
const hexColorBtn = document.querySelector('#hexBtn');
const bgColor = document.querySelector('body');
const hexCode = document.querySelector('#hexColor');
const copyBtn = document.querySelector('#copy-btn');
hexColorBtn.addEventListener('click', function () {
hexColor = '#';
for (let i = 0; i < 6; i++) {
const randomColor = Math.floor(Math.random() * hexNumbers.length);
hexColor += hexNumbers[randomColor];
}
bgColor.style.backgroundColor = hexColor;
hexCode.innerHTML = hexColor;
hexCode.value = hexColor;
});
copyBtn.addEventListener('click', function () {
navigator.clipboard.writeText(hexCode.value);
alert(`${hexCode.value} Copied!`);
});