beginner here.
Since days I try to build an etch-a-sketch board with 32 boxes, 16 columns and 16 rows. The only thing I end up with is 32 boxes in a row or in a column. I don't know where the error is, in the script, css or the html so I included all three in the post.
Any help is appreciated!
Here is the code:
document.addEventListener('DOMContentLoaded', () => {
const grid = document.querySelector('.grid');
//const message = document.querySelector('#message');
//MAKE THE BOARD
function makeBoard() {
for (let i = 0; i <= 16; i++ ) {
const squareCol = document.createElement('div');
squareCol.className = 'squareCol';
squareCol.setAttribute('data-id',i)
grid.appendChild(squareCol);
}for(let j = 0; j <= 16; j++){
const squareRow = document.createElement('div');
squareRow.className = 'squareRow';
squareRow.setAttribute('data-id',j)
grid.appendChild(squareRow);
}
}
makeBoard();
})
body {
margin: 0;
padding: 0;
}
.container {
display: flex;
justify-content: center;
align-items: center;
height: 618px;
width: 618px;
}
.grid {
display: flex;
justify-content: center;
align-items: center;
}
.squareRow, .squareCol {
display: flex;
justify-content: center;
align-items: center;
height: 10px;
width: 10px;
border: solid black 1px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Etch-a-Sketch</title>
<script src="script.js" defer></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<span class="grid"></span>
</div>
<div id="message"></div>
</body>
</html>