How come this if statement doesn't work (codepen included)

A Pen by Trenton (codepen.io)

the function at the very bottom of my JS file called “checkForEnd” is not working as intended and I’m not sure why?

basically, all I want it to do is check to see if there are any more cards left in the array and if it’s at the last card then set the array Index back to 0.

what is wrong with my code?

Thank you for the response, I’m trying to work on fixing this.

I tried to do this just to see if it would work and the arrayIndex matches up and hits 3 but nothing happens.

function incrementArrayIndex() {
    ArrayIndex++
    renderCards()
    console.log(ArrayIndex)
}
function decrementArrayIndex() {
    ArrayIndex--
    renderCards()
    console.log(ArrayIndex)
}

function checkForEnd() {
    if (ArrayIndex === 3) {
        ArrayIndex = 0
        renderCards()
    }
}

I’m trying to prepare myself for a project I want to do but I need to understand this better before I do so.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.