Exercise Set 4

Exercise 2 of 6

Decrease the counter when the button is clicked.


<button id="decreaseCounterButton">Decrease counter</button>
<p id="counterParagraph">Counter: 0</p>


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

var counter = 0;

decreaseCounterButton.addEventListener("click", decreaseCounter);

function decreaseCounter() {
    // your code will appear here
    counterParagraph.innerHTML = "Counter: " + counter;

You must be signed in to type your code.

Last exercise Next exercise