I am creating randomly fading squares on the image. They end up one by one partially revealing the image. This function was meant to hide random squares one by one but it is hiding them abnormally.
setInterval(disappearingBoxes, 500);
function disappearingBoxes() {
for (let i = 0; i < boxes.children.length; i++) {
i = Math.floor(Math.random() * 16).toFixed()
if (!boxes.children[i].classList.contains('hidden') && boxes.children[i].id === i) {
boxes.children[i].removeAttribute('id');
if (boxes.children[i].getAttribute('id') === null) {
boxes.children[i].classList.add('hidden')
} else {
let newI = Number(Math.floor(Math.random() * 16).toFixed());
boxes.children[newI].classList.add('hidden')
}
}