JSFiddle - React, Tailwind, and code Playground

by Augustus Yuan

HTML

<div id="timer"></div>

JavaScript

const timerEl = document.getElementById("timer");

const totalSeconds = 10;


timerEl.innerHTML = currentSecond;

let currentSecond = totalSeconds;
intervalId = setInterval(() => {
  timerEl.innerHTML = currentSecond;
  currentSeconds--;
}, 1000)

// time out for totalSeconds
timeoutId = setTimeout(() => {
	clearInterval(intervalId)
}, totalSeconds * 1000)