Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Vanilla Javascript image thumbnail gallery Reply To: Vanilla Javascript image thumbnail gallery

#265922
Shikkediel
Participant

The line you posted uses the modulo operator %. It’s handy to reduce a number to a remainder, after subtracting a multitude of the number that follows. So for example:

17 % 3 = 2

Because the maximum multitude of 3 that can be subtracted is 3 x 5 = 15, the remainder then is 2. In the script, it keeps the number that will be matched with an image between zero and the amount of images available (minus one because they are zero indexed).

Not sure that helps. Hard to explain.