JSFiddle - React, Tailwind, and code Playground

by raviteja gunda

HTML

<script src=""></script>
<div id="timer">0</div>
<br>
<div>
<button id="start" onclick="start()">Start</button>
<button id="stop" onclick="stop()">Stop</button>
<button id="reset" onclick="reset()">reset</button>
</div>

JavaScript

let interval;
let timerValue = document.getElementById("timer").textContent;

function start(){
	 interval = setInterval(() => {
         timerValue++;
         document.getElementById("timer").innerHTML = timerValue;
      },1000) 
}

function stop(){
	clearInterval(interval);
}

function reset(){
		clearInterval(interval);
    document.getElementById("timer").innerHTML = 0;
    
}