JSFiddle - React, Tailwind, and code Playground

by the_o

HTML

<span class="text-center"><span class="top-line">A heading here</span><br><span class="bottom-line">There once was a...<br>
 <span id="changeTextMobile"></span></span>
          </span>

JavaScript

var text = ["carrot", "potato", "tomato", "lettuce", "radish", "cabbage", "melon", "cucumber"];
    var elem = document.getElementById("changeTextMobile");

    var counter = 0;
    function rotate_text()
    {
        elem.innerHTML = text[counter];
        if (counter < 8){
            counter++
            window.setTimeout(rotate_text, 1200);
        }
        if(counter == 8) {
          counter = 0;
        }
    }  

rotate_text();