Im just trying to put a chronometer in html , but in the first 'if' of the method cronometro() the value of this.centesimas is undefine, and I really dont understand why because I declared these vars at the constructor of the class.
class NotaView {
constructor () {
this.centesimas = 0;
this.segundos = 0;
this.minutos = 0;
}
startCronometro() {
this.control = setInterval(this.cronometro,10);
}
cronometro () {
this.Centesimas = document.getElementById("Centesimas");
this.Segundos = document.getElementById("Segundos");
this.Minutos = document.getElementById("Minutos");
if (parseInt(this.centesimas) < 99) {
parseInt(this.centesimas++);
if (parseInt(this.centesimas) < 10) { this.centesimas = "0" + parseInt(this.centesimas) }
this.Centesimas.innerHTML = ":" + parseInt(this.centesimas);
console.log(this.centesimas)
}
if (parseInt(this.centesimas) == 99) {
this.centesimas = -1;
}
if (parseInt(this.centesimas) == 0) {
parseInt(this.segundos ++);
if (parseInt(this.segundos) < 10) { this.segundos = "0" + parseInt(this.segundos )}
this.Segundos.innerHTML = ":" + parseInt(this.segundos);
}
if (parseInt(this.segundos) == 59) {
this.segundos = -1;
}
if ( (parseInt(this.centesimas) == 0)&&((this.segundos) == 0) ) {
parseInt(this.minutos++);
if (parseInt(this.minutos) < 10) { this.minutos = "0" + parseInt(this.minutos )}
this.Minutos.innerHTML = ":" + parseInt(this.minutos);
}