-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
28 lines (25 loc) · 933 Bytes
/
app.js
File metadata and controls
28 lines (25 loc) · 933 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
let btn = document.querySelector("button");
let boxes = document.querySelectorAll(".colors");
boxes.forEach(box => {
let lockBtn = box.querySelector(".lock-btn");
lockBtn.addEventListener("click", () => {
box.classList.toggle("locked");
lockBtn.textContent = box.classList.contains("locked") ? "🔓" : "🔒";
});
});
btn.addEventListener("click", () =>{
boxes.forEach(box => {
if (box.classList.contains("locked")) return;
let randomColor = getRandomColor();
let head = box.querySelector("h3");
let colorDiv = box.querySelector("div");
head.innerText = randomColor;
colorDiv.style.backgroundColor = randomColor;
});
});
function getRandomColor(){
let red = Math.floor(Math.random()*225);
let green = Math.floor(Math.random()*225);
let blue = Math.floor(Math.random()*225);
return `rgb(${red}, ${green}, ${blue})`;
}