Skip to content
Advertisement

Increment array up to max items

I’ve written this code. It rotates two divs like a card flip using css transform every 1000ms and displays new text in the div, which is drawn from an array. It runs infinitely.

But once the array reaches its end I get an ‘undefined’ value because the i++ is incrementing on the final array item. I have been going crazy trying to figure out how to prevent that. Any help?

Codepen: https://codepen.io/warpigs666/pen/OJpBKdy

JavaScript

Advertisement

Answer

This is a job for setInterval

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement