Advertisement
renatoknot

Cronometro JS

Aug 25th, 2021 (edited)
1,209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Crie um cronometro utilizando o setInterval. Deve ser possรญvel
  2. // iniciar, pausar e resetar
  3.  
  4. // selecionando os botรตes do cronomentro
  5. const iniciar = document.querySelector(".iniciar");
  6. const pausar = document.querySelector(".pausar");
  7. const resetar = document.querySelector(".resetar");
  8.  
  9. // Span onde mostra o cronometro rolando
  10. const tempo = document.querySelector(".tempo");
  11.  
  12. iniciar.addEventListener("click", iniciarTempo);
  13. pausar.addEventListener("click", pausarTempo);
  14. resetar.addEventListener("click ", resetarTempo);
  15.  
  16. let i = 0;
  17. let timer;
  18.  
  19. function iniciarTempo() {
  20.   timer = setInterval(() => {
  21.     tempo.innerText = i++;
  22.   }, 1000);
  23.   iniciar.setAttribute("disabled", "");
  24. }
  25.  
  26. function pausarTempo() {
  27.   clearInterval(timer);
  28.   iniciar.removeAttribute("disabled");
  29. }
  30.  
  31. function resetarTempo() {
  32.   tempo.innerText = 0;
  33.   i = 0;
  34.   console.log("resetou");
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement