Last active
July 28, 2019 15:23
-
-
Save ANUPAMCHAUDHARY1117/f5a992eeafc1fd94568dd10be16f5fff 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 Player { | |
constructor(name){ | |
this.name = name; | |
this.goalsScored = 0; | |
this.chances = 10; | |
} | |
hit(){ | |
if(this.chances === 0){ | |
return console.log("Game is over"); | |
} | |
this.goalsScored++; | |
this.chances--; | |
} | |
miss(){ | |
if(this.chances === 0){ | |
return console.log("Game is over"); | |
} | |
this.chances--; | |
} | |
} | |
class OutFieldPlayer extends Player{ | |
constructor(name){ | |
super(name); | |
this.savesMade = 0; | |
} | |
save(){ | |
this.savesMade += 1; | |
} | |
} | |
var DeGea = new OutFieldPlayer("DeGea"); | |
DeGea.save(); | |
DeGea.hit(); | |
console.log(DeGea.savesMade); //1 | |
console.log(DeGea.goalsScored); //1 | |
var Ronaldo = new Player("Christiano Ronaldo"); | |
Ronaldo.hit(); | |
console.log(Ronaldo.goalsScored) //1 | |
console.log(Ronaldo.chances) //9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment