I'm doing a web application:Pomodoro.
I created a class. But I can't access the function in this this.countdown = setInterval(timer,1000)
.
I writed "this.timer". This way, the error does not returning, but the function does not working. How should I do ?
class Pomodoro{
constructor(){
this.countdown = 0;
this.seconds = 1500;
this.workTime = 25;
this.breakTime = 5;
this.isBreak = true;
this.isPaused = true;
this.minutes = Math.floor(this.seconds / 60);
this.remainderSeconds = this.seconds % 60;
};
start(){
clearInterval(this.countdown);
this.isPaused = !this.isPaused;
if(!this.isPaused){
this.countdown = setInterval(timer,1000);
};
};
reset(){
clearInterval(this.countdown);
this.seconds = this.workTime*60;
this.countdown = 0;
this.isBreak = true;
this.isPaused = true;
};
timer(){
this.seconds --;
if(this.seconds < 0){
clearInterval(this.countdown);
this.seconds = (this.isBreak ? this.breakTime : this.workTime) * 60;
}
};
}
let pomodoro = new Pomodoro();
function Update(){
pomodoro.start();
pomodoro.timer();
}
window.setInterval(Update, 100);