Skip to content

Instantly share code, notes, and snippets.

@ANUPAMCHAUDHARY1117
Last active July 28, 2019 14:26
Show Gist options
  • Save ANUPAMCHAUDHARY1117/17966e1f649d9812b2fb58feb14d4849 to your computer and use it in GitHub Desktop.
Save ANUPAMCHAUDHARY1117/17966e1f649d9812b2fb58feb14d4849 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--;
}
}
var Ronaldo = new Player("Cristiano 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