Exercise Set 13

Exercise 1 of 6

Watch the dictionary video. Add the definition to the dictionary when the button is clicked.

HTML

<input type="text" placeholder="word" value="elephant" id="wordInput">
<input type="text" placeholder="definition" value="a big animal" id="definitionInput">
<button id="addWordButton">Add word</button>
<p id="wordParagraph"></p>

JavaScript

var wordInput = document.getElementById("wordInput");
var definitionInput = document.getElementById("definitionInput");
var addWordButton = document.getElementById("addWordButton");
var wordParagraph = document.getElementById("wordParagraph");

var dictionary = {};

addWordButton.addEventListener("click", addWord);

function addWord() {
    // your code will appear here
    wordParagraph.innerHTML = wordInput.value + ": " + dictionary[wordInput.value];
}

You must be signed in to type your code.

Last topic Next exercise