Basically what I’m trying to do is to step through each ‘div’ element and one by one change the background color to red and then back to it’s default color once it has passed each ‘div’. It should look like one animated red box going left to right, over and over again. I can’t figure out the logic for this. How can I step through each div and change the color to red? I tried ‘setInterval’ but it just fills all the divs with red. So I’m thinking somehow I have to change the color one by one, but I’m not sure how to break this down. I noticed that if I do modulo on the array of divs I can get the first div to be red, so I don’t know if I’m on the right track, but now I’m basically stuck. I also thought that maybe if I create divs each with a unique ID that I would be able to do something with that but that went nowhere as well. How can I break this down logically with Javascript? What am I am doing wrong?
I didn’t think that the number of divs mattered when doing the comparison, I should of thought about it. Also one thing that doesn’t make sense to me is the
loops.to
part of the setTimeout. What is
.to
doing? How is that making the code work, is it a method?
Yeah I understand that setTimeout makes a delay but why do you have to use ‘.to’ after loops? I don’t see .‘to’ in the javascript reference. Where is ‘.to’ coming from?