I have a simple chessboard created with JavaScript and I want to add letters and numbers to the sides of my board so it will look like real chessboard. I've tried using for loop to add elements with letters and numbers but conditions seem to be false, because it didn't work. Here is my HTML code:
let table = document.createElement("table");
for (let i = 8; i > 0; i--) {
let tr = document.createElement('tr');
let number = document.createElement('td');
number.className = 'number';
number.innerHTML = i;
tr.appendChild(number);
for (let j = 0; j < 8; j++) {
let td = document.createElement('td');
if (i % 2 == j % 2) {
td.className = "white";
} else {
td.className = "black";
}
tr.appendChild(td);
}
table.appendChild(tr);
}
document.body.appendChild(table);
* {
margin: 0;
padding: 0;
}
table {
border-spacing: 0;
margin: 20px 20px;
}
.black {
width: 38px;
height: 38px;
background: black;
border: 1px solid transparent;
}
.white {
width: 38px;
height: 38px;
background: white;
border: 1px solid black;
}
.number {
padding-right: 10px;
font-size: 18px;
font-weight: bold;
}