Created
August 14, 2018 21:58
-
-
Save minmaxdata/156020e2e844933b35688bbb1e72c7e9 to your computer and use it in GitHub Desktop.
class keyword created by minmaxdata - https://repl.it/@minmaxdata/class-keyword
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Animal { | |
constructor(name, energy) { | |
this.name = name | |
this.energy = energy | |
} | |
eat(amount) { | |
console.log(`${this.name} is eating.`) | |
this.energy += amount | |
} | |
sleep(length) { | |
console.log(`${this.name} is sleeping.`) | |
this.energy += length | |
} | |
play(length) { | |
console.log(`${this.name} is playing.`) | |
this.energy -= length | |
} | |
} | |
const leo = new Animal('Leo', 7) | |
const snoop = new Animal('Snoop', 10) | |
leo.eat(10) | |
snoop.play(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment