JSFiddle - React, Tailwind, and code Playground

HTML

<body>
    <p >Spell a sentence backwards.</p>
    <input id="numb">
    <button type="button" onclick="myFunction()">Submit</button>
    <p id="demo"></p>
  </body>

JavaScript

function myFunction() {
    var sentence, text;
    sentence = document.getElementById("numb")
    sentence = sentence.replace( /^\s+|\s+$/g, " " )
    sentence = sentence.replace( /\s+/g, " " );
    
    var words = sentence.split(" ");
        words = words.reverse();
        sentence = words.join(" ");
    		document.getElementById("demo").innerHTML = text;
}