-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
48 lines (36 loc) · 1.17 KB
/
Copy pathscript.js
File metadata and controls
48 lines (36 loc) · 1.17 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
const mainBox = document.querySelector('.main-box');
const button = document.querySelector('button');
button.addEventListener('click', () => {
const numberBoxes = Number(prompt('Type the number of boxes per side'));
if (numberBoxes < 100) {
mainBox.innerHTML = '';
renderBoxes(numberBoxes, numberBoxes);
} else {
alert('Type a number less than 100')
}
})
function renderBoxes(height=16, width=16) {
mainBox.style.height = `480px`;
console.log(mainBox.style.height)
mainBox.style.width = `480px`;
for (let i = 0; i < height; i++) {
for (let j = 0; j < width; j++) {
const box = createBox();
box.style.height = `${480 / height}px`;
box.style.width = `${480 / height}px`;
mainBox.appendChild(box);
}
}
}
function createBox() {
const box = document.createElement('div');
box.setAttribute('class', 'box');
box.addEventListener('mouseover', () => {
box.style.backgroundColor = `rgb(${randomNumber()}, ${randomNumber()}, ${randomNumber()})`;
})
return box;
}
function randomNumber() {
return Math.floor(Math.random() * 256);
}
renderBoxes()