-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
29 lines (24 loc) · 866 Bytes
/
main.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
25
26
27
28
29
const container = document.getElementById("container");
const gridItem = document.getElementsByClassName('grid-item');
const btn = document.getElementById('popupbtn');
function makeRows(rows, cols) {
container.style.setProperty('--grid-rows', rows);
container.style.setProperty('--grid-cols', cols);
for (let c = 0; c < rows * cols; c++) {
let cell = document.createElement("div");
cell.innerText = c + 1;
cell.className = "grid-item";
container.appendChild(cell);
}
}
// makeRows(16, 16);
btn.addEventListener('click', callback);
function callback() {
const gridSize = prompt("Enter the number of grids per side: ");
const gridSizeNum = parseInt(gridSize);
if (Number.isNaN(gridSizeNum) || gridSizeNum <= 0) {
alert("Invalid input. Please enter a valid positive number.");
return;
}
makeRows(gridSizeNum, gridSizeNum);
}