-
-
Notifications
You must be signed in to change notification settings - Fork 524
/
script.js
24 lines (20 loc) · 804 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
const container = document.getElementById("container");
const colors = ["#056CF2", "#05AFF2", "#F2E205", "#F28705", "#A62103"];
const SQUARES = 500;
const getRandomColor = () => colors[Math.floor(Math.random() * colors.length)];
const setColor = (square) => {
const color = getRandomColor();
square.style.background = color;
square.style.boxShadow = `0 0 2px ${color}, 0 0 10px ${color}`;
};
const removeColor = (square) => {
square.style.background = "#1d1d1d";
square.style.boxShadow = "0 0 2px #000";
};
for (let i = 0; i < SQUARES; i++) {
const square = document.createElement("div");
square.classList.add("square");
square.addEventListener("mouseover", () => setColor(square));
square.addEventListener("mouseout", () => removeColor(square));
container.appendChild(square);
}