-3
Countdown timer doesn’t stop when it reaches "0". I need the timer to stop when it reaches "0" and when clicking on the "start" button it starts with the set value, which is "1 min" and decreases to "0" again. Stop and Add Buttons 1 min are working.
Below follows codes of buttons:
this.iniciarCronometro = this.iniciarCronometro.bind(this);
this.pararCronometro = this.pararCronometro.bind(this);
this.tempoFormatado = this.tempoFormatado.bind(this);
this.somarUmSegundo = this.somarUmSegundo.bind(this);
this.state = {
contadorSegundo: 0,
contadorMinuto: 1,
};
}
iniciarCronometro() {
var intervalId = setInterval(this.somarUmSegundo, 100);
this.setState({
intervalId: intervalId,
});
}
pararCronometro() {
clearInterval(this.state.intervalId);
this.setState({
contadorSegundo: 0,
contadorMinuto: 1,
});
}
somarUmMinuto() {
this.setState({
contadorMinuto: this.state.contadorMinuto + 1,
});
}
The Code below makes the chronometer work. The way it is implemented the counter does not stop when it reaches "0". I need it to stop when I reset and when I call the start function it starts from the set value " 1".
somarUmSegundo() {
let segundos = this.state.contadorSegundo;
let minutos = this.state.contadorMinuto;
minutos == 1 || segundos > 0;
if (segundos == 0) {
segundos = 59;
minutos = minutos - 1;
} else {
segundos = segundos - 1;
}
this.setState({
contadorSegundo: segundos,
contadorMinuto: minutos,
});
}
Your question is not very clear, have to point out more details?
– Francisco
@Francisco updated the code and put more information.
– Philipe Said
Dude, now you have too much information kk. If possible structure the question following the model of [mcve].
– Francisco
@Francisco updated.
– Philipe Said