Exercise Set 7

Exercise 1 of 6

Watch the array video. Add the text box value to the array when the button is clicked.


<input type="text" placeholder="word" value="hello" id="wordInput">
<button id="addWordButton">Add word</button>
<p id="wordsParagraph"></p>


var wordInput = document.getElementById("wordInput");
var addWordButton = document.getElementById("addWordButton");
var wordsParagraph = document.getElementById("wordsParagraph");

var words = [];

addWordButton.addEventListener("click", addWord);

function addWord() {
    // your code will appear here
    wordsParagraph.innerHTML = words;

You must be signed in to type your code.

Last topic Next exercise