Cycling Through Images using the JavaScript Remainder Operator

2 months ago
8

Learn how to use the remainder operator (percent sign, aka modulo) to go from the last image to the first image.

Every time you click the next button, the current image index increments. However, it goes beyond the number of elements in the array of image URLs. So we have to reset that index back to 0 when you are seeing the last image and click next.

Loading comments...