Skip to content

Instantly share code, notes, and snippets.

@classmember
Created September 15, 2017 01:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save classmember/dba6e59681a20cfb6d028efac28666c3 to your computer and use it in GitHub Desktop.
Save classmember/dba6e59681a20cfb6d028efac28666c3 to your computer and use it in GitHub Desktop.
/**
* @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