-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
123 lines (96 loc) · 3.05 KB
/
script.js
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
var timeupSound = new Audio("./assets/sounds/time-up.mp3")
var contador = document.getElementById("contador");
var execucao = document.getElementById("execucao");
var pauseBtn = document.getElementById("pauseBtn");
var comecarBtn = document.getElementById("comecarBtn");
var digito4 = document.getElementById("minDec");
var digito3 = document.getElementById("minUni");
var digito2 = document.getElementById("segDec");
var digito1 = document.getElementById("segUni");
var counting = false;
var clockInterval;
resetar();
function resetar(){
clearInterval(clockInterval);
digito1.value = 0;
digito2.value = 0;
digito3.value = 0;
digito4.value = 0;
counting = false;
pauseBtn.innerText = "Pausar";
pauseBtn.style.display = "none";
comecarBtn.disabled = true;
comecarBtn.style.display = "inline";
}
function pausar(){
if(counting == true){
pauseBtn.innerText = "Continuar";
counting = false;
clearInterval(clockInterval);
}
else if (counting == false) {
pauseBtn.innerText = "Pausar";
counting = true;
clock();
}
}
function comecar(){
if (digito1.value > 9) {
digito1.value = 9;
}
if (digito2.value > 5) {
digito2.value = 5;
}
if (digito3.value > 9) {
digito3.value = 9;
}
if (digito4.value >= 6) {
digito4.value = 6;
digito1.value = 0;
digito2.value = 0;
digito3.value = 0;
}
pauseBtn.disabled = false;
counting = true;
clock();
pauseBtn.style.display = "inline";
comecarBtn.style.display = "none";
}
function clock(){
clockInterval = setInterval(() => {
if(counting == true){
if (digito1.value >= 0) {
digito1.value--;
}
if(digito1.value < 0 && digito2.value >= 0){
digito1.value = 9
digito2.value--;
}
if(digito2.value < 0 && digito3.value >= 0){
digito2.value = 5
digito3.value--;
}
if (digito3.value < 0 && digito4.value >= 0){
digito3.value = 9;
digito4.value--;
}
if((digito1.value + digito2.value + digito3.value + digito4.value) == 0){
clearInterval(clockInterval);
timeupSound.play();
counting = false;
alert("Acabou o tempo!");
console.log("STOP RUNNING");
}
}
console.log(digito1.value);
console.log(counting);
}, 1000);
}
setInterval(() => {
if((digito1.value + digito2.value + digito3.value + digito4.value) == 0){
comecarBtn.disabled = true;
}
else if((digito1.value + digito2.value + digito3.value + digito4.value) != 0){
comecarBtn.disabled = false;
}
}, 200);