JSFiddle - React, Tailwind, and code Playground

Random Loop Terms

by Jennifer Perrin

HTML

<p>eg. <span>Envato</span></p>

JavaScript

var $target = $("p span"), // The target element
    initialTerm = $target.text(), // The first term
    terms = ["CodeCanyon", 
             "ThemeForest", 
             "GraphicRiver", 
             "PhotoDune", 
             "ActiveDen", 
             "AudioJungle", 
             "VideoHive", 
             "3DOcean"
            ], // Our list of terms
    changeTerms = setInterval(function() { // Term Changer function
        
        var random = Math.floor( Math.random() * terms.length ); // random number from 0 to the number of terms in our list
        $target.text(terms[random]); // Change term
    
    }, 2000); // All that happen in an interval of 2 seconds
terms.push(initialTerm); // We add the first term into our list of terms since we want it to appear again when the loop happens