Skip to content

Commit

Permalink
✔️ dynamic squares generation in the grid from user prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
sameem420 committed Mar 20, 2024
1 parent 6ebcd30 commit 0614a67
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions JavaScript/project-Etch-a-Sketch/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ const container = document.querySelector("#container");
let rows = document.getElementsByClassName("gridRow");
let cell = document.getElementsByClassName("cell");
const btnClear = document.querySelector("#btnClear");
const btnNew = document.querySelector("#btnNew");

let size = 0;

btnNew.addEventListener("click", function () {
size = +prompt("number of squares per side for the new grid (Max : 100)");

Array.from(rows).forEach((item) => {
container.removeChild(item);
});

makeRows(size);
makeColumns(size);
});

function makeRows(rowsSize) {
for (let r = 0; r < rowsSize; r++) {
Expand Down
1 change: 1 addition & 0 deletions JavaScript/project-Etch-a-Sketch/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<link rel="stylesheet" href="style.css" />
</head>
<body>
<button style="margin-bottom: 5px" id="btnNew">Create new Grid</button>
<div id="container"></div>
<button id="btnClear">Clear</button>
</body>
Expand Down
9 changes: 9 additions & 0 deletions JavaScript/project-Etch-a-Sketch/style.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
#container {
min-width: 960px;
}
.cell {
border: 1px solid gray;
min-width: 20px;
Expand Down

0 comments on commit 0614a67

Please sign in to comment.