See the answerWrite a setInterval() function that increases the count by 1 and displays the new count in counterElement every 300 milliseconds. Call clearInterval() to cancel the interval when the count displays 5.var count = 0;var counterElement = document.getElementById("counter");counterElement.innerHTML = count;/* Your solution goes here*/

Respuesta :

Answer:

var count = 0;

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

counterElement.innerHTML = count;

var interval = setInterval(function () {

   count++;

   counterElement.innerHTML = count;

   if (count === 5) {

       clearTimeout(interval);

   }

}, 300);

Explanation:

  • Initialize the count and get access to the counter element using the id.
  • Assign the value of count to counterElement document.
  • Use the setInterval function to set the timer and increases the count by 1.
  • Check if the value of count is equal to 5, then call the built-in clearTimeout function by passing it the interval variable.

ACCESS MORE