Created
March 24, 2019 18:18
-
-
Save Damimd10/6fe2de1e2523c91e465c48ad406ed459 to your computer and use it in GitHub Desktop.
This file contains 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 Hero { | |
constructor(name) { | |
this.name = name | |
} | |
prepareForBattle(increaseCount) { | |
console.log(`I am ${this.name}! Let's go fighting!`) | |
increaseCount() | |
} | |
} | |
class Battle { | |
constructor(heroes) { | |
this.heroes = heroes | |
this.preparedHeroesCount = 0 | |
this.heroes.forEach(heroe => { | |
heroe.prepareForBattle(this.increaseCount) | |
}) | |
} | |
increaseCount() { | |
this.preparedHeroesCount++ | |
console.log(`${this.preparedHeroesCount} heroes are now ready to fight!`) | |
} | |
} | |
const firstHero = new Hero('Flash') | |
const secondHero = new Hero('Thor') | |
new Battle([firstHero, secondHero]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment