The current problem now is i changed the function i got from the awnser but the previous one doesn’t work.
function getPrev(currPhotoId) {
var i = currPhotoId - 1;
i %= album.length;
while ( album[i].disabled ) {
i--;
i %= album.length;
}
return i;
}
The output works as long it is above 0
TypeError: album[i] is undefined
undefined = "0"
while ( album[i].disabled )
The following logic is pretty simple. The trick is to just keep iterating until you find one that is not disabled, using modulus (
%) to perform the loop-around when you hit the end.Just make sure there’s at least one that is enabled or this will loop infinitely. 🙂