const chessBoard = document.querySelector("#board");
let aSwitch = true; // define a switch to create black & white square
let increment = 1; // will be use to determine the row of the board
for (let i = 0; i < 64; i++) {
let square = document.createElement("div");
square.classList.add("square");
if (aSwitch === true) {
square.classList.add("white");
aSwitch = false;
} else {
square.classList.add("black");
aSwitch = true;
}
if (i === 7 * increment) {
increment++;
aSwitch = !aSwitch;
} // ensure that the next row will follow a checkered pattern
chessBoard.append(square);
}
output:

however if i change the sequence to i === 8 * increment, the output is:

Please help me understand this phenomenon since i am very dummb and confused, thanks alot!
I did try using the internet, and best i came up with was that the square was in a 0-index sequence, but when i try using the equation 7 * increment, the output was also wrong:

Your approach is not correct:
7 * incrementwill give 7, 14, 21, ... So you are checking the 8th square, but then the 15th, the 22nd and so on.8 * incrementwill give 8, 16, 24, ... Again. this is not what you want.You need to use the remainder operator
%: the expressioni % 8 === 7will be true at the 8th, 16th, 24th, ... square.