26.3k views
4 votes
Write a setInterval() function that increases the count by 1 and displays the new count in counterElement every 100 milliseconds. Call clearInterval() to cancel the interval when the count displays 4.

User Dwosk
by
7.7k points

1 Answer

4 votes

Answer:

var count = 0;

var counterElement = document.getElementById("counter");

counterElement.innerHTML = count;

var interval = setInterval(function () {

count++;

counterElement.innerHTML = count;

if (count === 4) {

clearTimeout(interval);

}

}, 100);

Step-by-step explanation:

User Ronnix
by
7.5k points