Exercise Set 7

Exercise 1 of 6

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

HTML

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

JavaScript

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