JSFiddle - React, Tailwind, and code Playground

by Gerald Gillespie

HTML

<!DOCTYPE html>
<html>
<body>

<p>Click the first button to display the current time, and the second button to stop the time.</p>
<button onclick="myFunction()">Try it</button>
<button onclick="myStopFunction()">Stop time</button>

<p id="demo"></p>

</body>
</html>

JavaScript

var myVar;
function myFunction()
{
myVar=setInterval(function(){myTimer()},1000);
}

function myTimer()
{
var d=new Date();
var t=d.toLocaleTimeString();
document.getElementById("demo").innerHTML=t;
}

function myStopFunction()
{
clearInterval(myVar);
}