I am trying to "navigate" correctly inside an array of functions by a "foward" and a "back" buttons with jQuery. I am having trouble with the back button which is navigating incorrectly.
var functions = [ function0, function1, function2, function3, function4, function5 ];
var index = 0;
$("#forward").click(function() {
functions[Math.abs(index % functions.length)]();
index++;
});
$("#back").click(function() {
functions[Math.abs(index % functions.length)]();
index--;
});
Here is the complete code: