I am trying to get a set of strings in an array to fade in and out, then change to the next string in the array. The code below skips directly to the third element in the array. I can't see how or why.
var msg = ["Test Number 1", "Test Numero Dos", "Test, the third"];
$( document ).ready(function(){
fade();
setInterval(fade, 15000);
});
function fade() {
var i;
for (i = 0; i < msg.length; ++i) {
$('#message').html(msg[i]);
$('#message').fadeIn(1000, function(){
$('#message').delay(30000).fadeOut(1000);
});
};
}
<div id="message" style="display:none;">TEST MESSAGE</div>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>