Created
September 15, 2017 01:55
-
-
Save classmember/dba6e59681a20cfb6d028efac28666c3 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
/** | |
* @file Defines Person class | |
* @version 1.0 | |
* @author Kolby Heacock <kolby@fasterdevops.com> | |
* @copyright Kolby Heacock 2017 | |
*/ | |
/** | |
* Representation of a person | |
* @class | |
* @example | |
* // returns "Hello. My name is Mario and I am 25 years old." | |
* var player1 = new Person('Mario', 1992); | |
* player1.greet(); | |
*/ | |
class Person { | |
/** | |
* Create a person. | |
* @param {string} name - name of the person | |
* @param {number} birthYear - birth year of the person | |
*/ | |
constructor(name, birthYear){ | |
this.name = name | |
this.birthYear = birthYear | |
} | |
/** | |
* Get person's age by subtracting current year by person's birth year. | |
* @return {number} person's age. | |
*/ | |
getAge(){ | |
return (new Date()).getFullYear() - this.birthYear | |
} | |
/** | |
* Get a greeting text identifying the peron's name and age. | |
* @return {string} "Hello. My name is {name} and I am {age} years old." | |
*/ | |
greet(){ | |
return 'Hello. My name is ' + this.name + ' and I am ' + this.getAge() + ' years old.' | |
} | |
} | |
let player1 = new Person('Mario', 1992) | |
player1.greet() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment