Exercise Set 12

Exercise 1 of 6

Show every letter in the word with a space between each letter. Treat a string like an array of characters.

HTML

<input type="text" placeholder="word" value="hello" id="wordInput">
<button id="showLettersButton">Show letters</button>
<p id="lettersParagraph">Letters:</p>

JavaScript

var wordInput = document.getElementById("wordInput");
var showLettersButton = document.getElementById("showLettersButton");
var lettersParagraph = document.getElementById("lettersParagraph");

showLettersButton.addEventListener("click", showLetters);

function showLetters() {
    var word = wordInput.value;

    for (var i = 0; i < word.length; i++) {
        // your code will appear here
    }
}

You must be signed in to type your code.

Last topic Next exercise