-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontador.ts
58 lines (55 loc) · 1.58 KB
/
contador.ts
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
47
48
49
50
51
52
53
54
55
56
57
58
export class MyTimer {
interval = null;
counter: number = 0;
element: HTMLElement = null;
element2: HTMLElement = null;
element3: HTMLElement = null;
constructor(e: HTMLElement, a: HTMLElement, c: HTMLElement) {
this.element = e;
this.element2 = a;
this.element3 = c;
}
start() {
this.counter = 0;
this.element.innerHTML = `${this.counter}s`;
let tempoRestante = 0;
let Acao: string = 'Descanso';
let ciclo = 0;
this.interval = setInterval(() => {
this.counter++;
tempoRestante = tempoRestante - 1;
if (ciclo < 9) {
if (tempoRestante <= 0) {
if (Acao === 'Exercitar!') {
Acao = 'Descanso';
tempoRestante = 11;
//tempoRestante = 6;
this.counter = 0;
} else if (ciclo < 8) {
Acao = 'Exercitar!';
tempoRestante = 21;
//tempoRestante = 11;
this.counter = 0;
ciclo = ciclo + 1;
} else {
tempoRestante = 0;
this.counter = 0;
Acao = `ACABOU!`;
clearInterval(this.interval);
ciclo = 0;
}
this.element2.innerHTML = `${Acao}`;
this.element3.innerHTML = `Ciclos: ${ciclo}`;
}
this.element.innerHTML = `${this.counter}s`;
console.log(tempoRestante);
}
}, 1000);
}
stop() {
this.counter = 0;
this.element.innerHTML = `${this.counter}s`;
this.element2.innerHTML = `Parado`;
clearInterval(this.interval);
}
}