Some time back someone helped me with some code. And in his code, he has the % operator.
I never have seen it. And I also can’t find a good explanation on youtube or google. I asked him and this is what he said.
`The % operator returns the integer remainder of dividing.
for(var i=0, s=’ABC’; i<9; i++) {
console.log(i, i%s.length, s[i%s.length])
}
I don’t really understand that too. especially I%s. And why is it returning a loop?
I code that I use is this
`const newDot = dots[(dots.length + counter – 1) % dots.length];
Can someone explane me who this works?
What I can understand or try to understand is this. (I have 4 dots and const counter = 1);
The length of the dots (4) + counter(1) – 1 % dots.length (4)
4 + 1 – 1 % 4 = 0 ?
4 + 2 -1 % 4 = 1.25 and % takes 1.25 and turns it into 1?
After I wrote this I am more lost hahah.