I'm making a simple HTML/CSS/JavaScript text demo on codePen and I'm having issues with looping a function in the JavaScript. Here's what I have so far.
function loop() {
var i;
for (i = 0; i < 4; i++) {
flicker();
}
var wait = (Math.random() * 4000);
setTimeout(loop, wait);
}
function flicker() {
$("#text").toggleClass('on');
}
loop();
If I take out the for loop, the text flickers. As soon as I add it back in, it freezes. Any help would be appreciated.
EDIT: The effect I'm trying to get is 2 to 4 quick flickers, a longer pause, and then another set of flickers. Think neon signs. The codepen link is here if it helps.