-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
36 lines (27 loc) · 1002 Bytes
/
Copy pathscript.js
File metadata and controls
36 lines (27 loc) · 1002 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
31
32
33
34
35
36
"use strict";
const colourBtn = document.querySelector(".colour-btn");
const hexBtn = document.querySelector(".hex-btn");
console.log(hexBtn);
const backgroundColorHexCode = generateRandomColor();
//random color will be freshly served
function generateRandomColor() {
return "#" + Math.floor(Math.random() * 16777215).toString(16);
}
// Logs the hex code and writes it
hexBtn.textContent = generateRandomColor();
console.log(generateRandomColor());
colourBtn.addEventListener("click", () => {
hexBtn.textContent = generateRandomColor();
document.body.style.backgroundColor = hexBtn.textContent;
});
// When you click the label
hexBtn.addEventListener("click", function () {
// Copies To Clipboard
navigator.clipboard.writeText(backgroundColorHexCode);
alert("Copied!");
});
// let z = generateRandomColor();
// document.body.style.backgroundColor = z;
// hexBtn.textContent = z;
hexBtn.textContent = generateRandomColor();
document.body.style.backgroundColor = hexBtn.textContent;