84.5k views
5 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 5.

User GScrivs
by
6.1k points

1 Answer

4 votes

Answer:

Some parts of your question is missing here is the missing part

var count = 0;

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

counterElement.innerHTML = count;

Answer : var interval = setInterval(function () {

count++;

counterElement.innerHTML = count;

if (count === 5) {

clearTimeout(interval);

}

}, 300);

Step-by-step explanation:

var interval = setInterval(function () {

count++;

counterElement.innerHTML = count;

if (count === 5) {

clearTimeout(interval);

}

}, 300);

User Ervi B
by
6.0k points