JSFiddle - React, Tailwind, and code Playground

by WladesKO

HTML

<!DOCTYPE html>
<html>
  <head>
    <title>Parcel Sandbox</title>
    <meta charset="UTF-8" />
  </head>

  <body>
    <p>Clique no botão abaixo para ver a hora atual.</p>
    <button onclick="horaAtual()">Iniciar Relógio</button>
    <h2 id="rel"></h2>

    <script src="src/index.js"></script>
  </body>
</html>

JavaScript

function horaAtual() {

  let hora = new Date().toLocaleTimeString();

  document.getElementById("rel").innerHTML = hora;

}
setTimeout(horaAtual, 2000); //método executa a função após 2 segundos