This snippet includes HTML:
<form>
<input id="input" type="text"/>
<button id="button"> Add! </button>
</form>
<div class="list"></div>
And here's the accompanying script:
var input = document.getElementById("input"); // store the element
var button = document.getElementById("button");
var myArray = [];
button.onclick = function alertUser (){
myArray.unshift(input.value); // adding the value
return myArray;
};
alertUser();
document.write(myArray);
An issue is that the array 'myArray' remains empty despite attempts to add elements. Seeking some insights on this matter, thank you!