-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
46 lines (35 loc) · 1.17 KB
/
Copy pathscript.js
File metadata and controls
46 lines (35 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const btn = document.querySelector('#btn-contar');
const dias = document.querySelector('#dias');
const hora = document.querySelector('#horas');
const min = document.querySelector('#min');
const seg = document.querySelector('#seg')
let tempoRestante;
let intervalId;
let d ;
let h;
let m;
let s;
const inciarContagem = () =>{
const tempoSelecionado = document.querySelector('#tempo');
tempoRestante = parseInt(tempoSelecionado.value);
let tempoUtil = tempoRestante * 86400
intervalId = setInterval(()=>{
if(tempoUtil != 0){
d = Math.floor(tempoUtil / 60 / 60 / 24);
h = Math.floor(tempoUtil / 60 / 60)%24;
m = Math.floor(tempoUtil / 60) %60;
s = Math.floor(tempoUtil)%60
tempoUtil--;
}else{
clearInterval()
}
atualizaContador();
},1000)
}
const atualizaContador = () =>{
dias.textContent = d < 10 ? '0' + d : d;
hora.textContent = h < 10 ? '0' + h : h;
min.textContent = m < 10 ? '0' + m : m;
seg.textContent = s < 10 ? '0' + s : s;
}
btn.addEventListener('click', inciarContagem)