Exercise Set 4

Exercise 6 of 6

Start an automatic counter when the button is clicked.

HTML

<button id="startCounterButton">Start counter</button>
<p id="counterParagraph">Counter: 0</p>

JavaScript

var startCounterButton = document.getElementById("startCounterButton");
var counterParagraph = document.getElementById("counterParagraph");

var counter = 0;

startCounterButton.addEventListener("click", startCounter);

function startCounter() {
    // your code will appear here
}

function increaseCounter() {
    counter = counter + 1;
    counterParagraph.innerHTML = "Counter: " + counter;
}

You must be signed in to type your code.

Show your answers to the instructor before moving on.

Last exercise Next topic First exercise