Been banging my head on this. I'm trying to take user-input via form and print out their sentence backwards. It's not working and I'm not sure exactly why.
I used some code from here for the reverse string function.
I tried lots of different string reverse functions but most of them were too complicated to understand, so fairly beginner here. :) Any help would be truly appreciated.
function myFunction() {
var sentence, text;
sentence = document.getElementById("numb")
sentence = sentence.replace( /^\s+|\s+$/g, " " )
sentence = sentence.replace( /\s+/g, " " );
var words = sentence.split(" ");a
words = words.reverse();
sentence = words.join(" ");
document.getElementById("demo").innerHTML = text;
}
<body>
<p >Spell a sentence backwards.</p>
<input id="numb">
<button type="button" onclick="myFunction()">Submit</button>
<p id="demo"></p>
</body>
. What is it that I'm missing? Here's what I have: https://jsfiddle.net/aw5tk1o3/
– Chris M Ferguson Aug 28 '17 at 06:22