Message from JavaScript discussions

April 2019

β€” Show code

β€” 

class Game {
constructor(pace, money){
this.startTime = 464;
this.pace = pace;
this.money = money;
this.interval = null;
}
hour(a){
a = Math.floor(this.startTime/60)
return (a > 23) ?a = 0 :a
};
minute(a){
a = this.startTime%60
return (a < 10) ?'0'+a :a }
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();}, this.pace)
}
pause(){
return clearInterval(this.interval)
}
resume(){
this.pause()
this.play()
}
manage(actions, duration) {
this.pause();
this.play(
...actions.length === 0
? [
() =>
console.error('no function was called')
]
: actions.slice(0, 3));
setTimeout(
() => this.resume(),
duration);
}
}
const newGame = new Game(1000, 10000);

const test =()=>newGame.pause()
setTimeout(test, 10000)

class Cat {
constructor(name){
this.name = name;
this.energy = 100;
this.hunger = 100;
this.fun = 0;
this.fat = 0;
this.str = 0
this.humor = 100

}
catManage(actions, duration){
Game.manage(actions, duration)
}
walk(howLong){
console.log(
${this.name} begun to walk)
console.log(this.energy)
const test = () => {
console.log(
${this.name} is walking now)}
this.energy -= 5
this.catManage([test], howLong*newGame.pace)

setTimeout(()=>console.log('finished'), howLong*newGame.pace)
}
}
const newCat = new Cat('Garfield')

newCat.walk(5)

β€” I will try, m getting hard time in css

β€” πŸ˜₯

β€” There is catManage() added to Cat proto

β€” That is the change

β€” CSS is actually the easiest imo so take your time

β€” It’s harder than js. πŸ˜‚

β€” Nope

β€” True,i find js easier than css

β€” Hard to do styling

β€” Positioning