could somebody help me to fully understand what is happening here please
let slideShowHandler = () => {
for(let i = 1; i <= mainElement.children.length; i++){
setTimeout(function(){
document.querySelector('#wrapper div:nth-of-type('+ i +')').style.display = "flex";
}, 3000 * i);
if(i == mainElement.children.length){
alert(i)
}
}
}
when I run the function, the alert comes up before all of the div's are displayed. I thought that it was waiting 3000ms * i and then updating i. but it looks like i goes to 4 and then the setTimeout function starts. Any explanation to how exactly this is working would be fantastic