I'm learning javascript and I'm trying to do an exercise where every half second a header's font will change. I got that working, but every one and awhile it will pick the same array number back to back. This makes the switch look like it paused. Here is my code so far:
var myFont = [ "times", "helvetica", "verdana", "georgia"];
setInterval(function(){
number = Math.floor(Math.random() * myFont.length);
document.getElementById('hi').style.fontFamily = myFont[number];
}, 500);
Would you push the number variable to an array then check it with an if statement? Tried it but couldn't quite figure it out. Any help is really appreciated!