for example i have this program calling functions some with set time outs, some function work just calling them (setTimeout(this.siguienteNivel, 1500); but others needed (the last ones of the code) an arrow function, (setTimeout(() =>this.iluminarSecuenciaFinal();}, 1000 * i);) if the arrow function is missing the function does not trigger in these specific cases, i dont understand why this differentiator, the program is in a class, i dont know if that makes a difference
this is a piece, the complete code is this if needed: https://github.com/moorooba/simon/blob/master/index.html
> elegirColor(ev) {
const nombreColor = ev.target.dataset.color;
const numeroColor = this.transformarColorANumero(nombreColor);
this.iluminarColor(nombreColor);
if (numeroColor === this.secuencia[this.subnivel]) {
this.subnivel++;
if (this.subnivel === this.nivel) {
this.nivel++;
this.eliminarEventosClick();
if (this.nivel === ULTIMO_NIVEL + 1) {
this.ganador();
} else {
setTimeout(this.siguienteNivel, 1500);
}
}
} else {
this.perdio();
}
}
// ganoElJuego() {
// swal("Platzi", "Felicitaciones, ganaste el juego!", "success").then(
// this.inicializar
// );
// }
// perdioElJuego() {
// swal("Platzi", "Lo lamentamos, perdiste :(", "error").then(() => {
// this.eliminarEventosClick();
// this.inicializar();
// });
// }
perdio() {
loser.classList.remove("hide");
setTimeout(this.startos, 1000);
this.eliminarEventosClick();
}
startos() {
loser.classList.add("hide");
boton.classList.remove("hide");
}
ganador() {
console.log("diparo");
this.eliminarEventosClick();
for (let i = 0; i < 4; i++) {
// setTimeout(this.iluminarSecuenciaFinal, 1000 * i);
setTimeout(() => {
this.iluminarSecuenciaFinal();
}, 1000 * i);
}
// setTimeout(this.ganoJuego, 4000);
setTimeout(() => {
this.ganoJuego();
}, 4000);
}
ganoJuego() {
console.log("ganojuego");
winner.classList.remove("hide");
// setTimeout(this.restart, 1500);
setTimeout(() => {
this.restart();
}, 1500);
}