Skip to content

Instantly share code, notes, and snippets.

@ANUPAMCHAUDHARY1117
Last active July 28, 2019 15:23
Show Gist options
  • Save ANUPAMCHAUDHARY1117/f5a992eeafc1fd94568dd10be16f5fff to your computer and use it in GitHub Desktop.
Save ANUPAMCHAUDHARY1117/f5a992eeafc1fd94568dd10be16f5fff to your computer and use it in GitHub Desktop.
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