How to set one minute counter in javascript?

Viewed 78347

In my project ,I have list of questions, for every question have three option answers.

After see the question if i want answer that question means click "show answer" button . when I click button ,counter starts for one minute after one minute error will show .

can any one help ?

5 Answers

// this is the simplest way to one mint counter .this is also use in angular and oops

var i=60;
function coundown(){
   setInterval(() => {
  if (this.i == 0) {
    return;
  }
  console.log(this.i--);

}, 1000);
}

// this function you can call when otp is comming or form submit and waiting for otp countdown

angular #javascript #typescript

you can try to use this

or visit for more details Demo

Demo2

function countdown() {
        var seconds = 59;
        function tick() {
          var counter = document.getElementById("counter");
          seconds--;
          counter.innerHTML =
            "0:" + (seconds < 10 ? "0" : "") + String(seconds);
          if (seconds > 0) {
            setTimeout(tick, 1000);
          } else {
            document.getElementById("verifiBtn").innerHTML = `
                <div class="Btn" id="ResendBtn">
                    <button type="submit">Resend</button>
                </div>
            `;
            document.getElementById("counter").innerHTML = "";
          }
        }
        tick();
      }
      countdown();
<div class="btnGroup">
        <span class="Btn" id="verifiBtn">
          <button type="submit">Verify</button>
        </span>
        <span class="timer">
          <span id="counter"></span>
        </span>
      </div>
      
      
      
      

Related