Message from JavaScript discussions

April 2019

— U placed all images in same div or in separate div?

— 

elxris TRGWII I ferther improved the code! There is no more manage function now there is manage method inside the proto of the class Game!

— In my case separate

— Nice 🎉

— U used css grid?

— Great

— Also note how I moved hour and minute out into a prototype method!

— And time into an instance variable instead of a global

— Important differences

— let time = null;
const func = 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()
}
tick(){
return this.startTime++
}
play(...func){

const queue = (...func)=>{
for(let f of func){
f()
}
}

this.interval = setInterval(()=>{
console.log(this.displayTime());
queue(...func)
this.tick()
console.log(time);
time++;}, 1000)
}
pause(){
return clearInterval(this.interval)
}
resume(){
this.pause()
this.play()
}
manage(actions, duration) {
this.pause()
let error = () => console.error('there was no function called');
if(actions.length >= 3){
let [first, second, third] = actions
this.play(first, second, third)
};
if(actions.length === 2){
let[first, second] = actions
this.play(first, second)
};
if(actions.length === 1){
let[first] = actions
this.play(first)
};
if(actions.length === 0){
let[] = actions
this.play(error);
};

const placeholder = () => this.resume()
setTimeout(placeholder, duration)
}
}
const newGame = new Game(1000, 10000);
time = newGame.startTime
const test =()=>newGame.pause()
setTimeout(test, 10000)

const test2 = () => console.log('walking')
const test3 = () => console.log('talking')
const test5 = () => console.log('shopping')


newGame.play()

const testing = () => newGame.manage([], 2000)
setTimeout(testing, 3000)


I want to be modest but I really feel proud of this code TRGWII

Message permanent page

— I even added a custom error if there is no action passed to the manage()

— Now you have reverted everything 🤦‍♂