Exercise Set 8

Exercise 1 of 6

Watch the loop video. Write the initialization to show the numbers 0 through 9.

HTML

<button id="showNumbersButton">Show numbers 0 through 9</button>
<p id="numbersParagraph">Numbers:</p>

JavaScript

var showNumbersButton = document.getElementById("showNumbersButton");
var numbersParagraph = document.getElementById("numbersParagraph");

showNumbersButton.addEventListener("click", showNumbers);

function showNumbers() {
    for (// your code will appear here; i < 10; i++) {
        numbersParagraph.innerHTML = numbersParagraph.innerHTML + " " + i;
    }
}

You must be signed in to type your code.

Last topic Next exercise