Last active
July 28, 2019 14:26
-
-
Save ANUPAMCHAUDHARY1117/17966e1f649d9812b2fb58feb14d4849 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--; | |
} | |
} | |
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