From fefb486d4564c0a99b472b9429afcd3d3eefcad3 Mon Sep 17 00:00:00 2001 From: didier amyot Date: Tue, 5 Dec 2023 12:46:35 -0500 Subject: [PATCH] added more stuff --- modules-examples/hockey.js | 48 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/modules-examples/hockey.js b/modules-examples/hockey.js index b2234b3..7fbaa5e 100644 --- a/modules-examples/hockey.js +++ b/modules-examples/hockey.js @@ -49,3 +49,51 @@ export class HockeyGame{ return "tie" } } + +/** + * Class representing a simple hockey player. The hockey player + * has a name (first and last) and a date of birth. + */ +class HockeyPlayer{ + /** + * the fist name of the player. + */ + firstName = "" + /** + * the last name of the player. + */ + lastName = "" + + /** + * the date of birth of the player. + */ + dateOfBirth = null; + + /** + * + * @param {String} firstName the first name of the player + * @param {String} lastName the last name of the player + * @param {Date} dateOfBirth the birth date of the player + */ + constructor(firstName, lastName, dateOfBirth){ + this.firstName = firstName; + this.lastName = lastName; + this.dateOfBirth = dateOfBirth; + } + + /** + * the full name of the player. + */ + get name(){ + return this.firstName + " " + this.lastName + } + + /** + * Returns the current age of the player in years. + */ + currentAge(){ + let now = Date.now(); + let numberOfMillisecondsPerYear = 365 * 24 * 60 * 60 * 1000; + return Math.floor((now - this.dateOfBirth.getTime()) / numberOfMillisecondsPerYear); + } +}