Hey there, I'm pretty new to JavaScript and I've run into an issue with my slides. Everything seems to work fine, but only after the second click. When I added a console log in my function, it appears on the first click, however the if/else statement doesn't kick in until the second one. Can't seem to figure out what's going wrong.
let index = 0;
function previousPage () {
console.log ('previous');
initialize();
if (index === 0){
index = spContainer.length;
spContainer[index-1].style.display = 'flex';
index--;
} else {
spContainer[index-1].style.display = 'flex';
index--;
}
}
function nextPage () {
console.log ('next');
initialize();
if (index === spContainer.length){
index = 0;
spContainer[index].style.display = 'flex';
index++;
} else {
spContainer[index].style.display = 'flex';
index++;
}
}
function initialize () {
spContainer.forEach (x => x.style.display = 'none');
}