function horaAtual() { setTimeout(function(){ let hora = new Date().toLocaleTimeString(); document.getElementById("rel").innerHTML = hora; }, 1000) }
<!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>