I have successfully implemented a jQuery code for creating a loop of "changing words" by referring to the solution provided in this Stack Overflow answer: jQuery: Find word and change every few seconds
My question is, how can I stop this loop after a certain amount of time? For example, after 60 seconds or once it has cycled through all the words in the loop?
(function() {
// List of words to cycle through:
var words = [
'Teacher',
'Principal',
'Guidance counselor',
'Teacher',
'School nurse',
'Teacher',
'School psychologist',
'Administrator'
],
i = 0;
setInterval(function() {
$('#dennaText').fadeOut(function() {
$(this).html(words[i = (i + 1) % words.length]).fadeIn();
});
// 2 seconds
}, 2000);
})();