I have a code snippet that allows users to enter words into an input box and store them in an array by clicking the Add Word
button. Once multiple words have been entered, users can click the Process Word
button to display all the words from the array. I need help with implementing this functionality efficiently. Additionally, I'm curious why the message "Field is empty" doesn't appear when nothing is entered in the input box.
function begin() {
var word = "List of words";
var i = returnword.length
if (userinput.length === 0) {
word = "Field is empty"
}
document.getElementById('message2').innerHTML = word
while (i--) {
document.getElementById('message').innerHTML = returnword[i] + "<br/>" + document.getElementById('message').innerHTML;
}
}
function addword() {
var arrword = [];
returnword = document.getElementById('userinput').value;
arrword.push(returnword);
}