Message from JavaScript discussions

April 2019

— It checks the time after the function is paused

— 

I feel like something it’s not all right. Could you please send a file or something with all the code?

— Let time = null;
class Game {
constructor(pace, money){
this.hour = (a) =>{
a = Math.floor(this.startTime/60)
return (a > 23) ?a = 0 :a
};
this.minute = (a) => {
a = this.startTime%60
return (a < 10) ?'0'+a :a }
this.startTime = 464;
this.pace = pace;
this.money = money; //12
this.interval = null;
this.process = null;
}
displayTime(){
return this.hour() +':'+this.minute()
}
ticking(){
return this.startTime++
}
play(){
this.interval = setInterval(()=>{
console.log(this.displayTime());
this.ticking()
time++;
console.log(time);
return time}, 1000)
return time
}
pause(){
return clearInterval(this.interval)
}
}

const newGame = new Game(1000, 10000);
const test =()=>newGame.pause()
setTimeout(test, 8000)

newGame.play(time)
time = newGame.startTime

const test2 = () => console.log(time)
setTimeout(test2,15000)

Message permanent page

— I'm not an expert but I know I got what I needed

— Ticking should probably just be tick

— Ok, if this is what you need and works for you it’s fine. But imagine having multiple instances of Game. And I think this is not a OOP pattern like you said you wanted.

Message permanent page

— Yeah naming functions and methods is causing me a real headache

— Just make them verbs

— DisplayTime -> getTime

— Could you change this code the way you feel it would be more OOP and paste it here?

— OOP is not a good goal imo

— I was trying to get to this result for six hours, so understand my euphoria 😅