COMP9633 - Assignment 1 + 2 solution

by Joshua Koudys

JavaScript

/* 100% grade: */
function Student(name, birthday) {
    this.name = name; // Optional
    this.birthday = birthday;
}
Student.prototype.checkIfBirthday = function(checkDate) {
    return this.birthday.getDate() == checkDate.getDate() && this.birthday.getMonth() == checkDate.getMonth();
}
Student.prototype.isTodayBirthday = function() {
    return this.checkIfBirthday(new Date());
}
/* End markable portion */

// Example code for testing -- not necessary to submit or marked.
var josh = new Student("Joshua Koudys", new Date("6, 4, 2014"));
console.log("Check if Feb 2nd is " + josh.name + "'s birthday: " + josh.checkIfBirthday(new Date("2015-02-02")));
console.log("Check if today is " + josh.name + "'s birthday: " + josh.isTodayBirthday());

/* Notes:
Student.name not strictly required, just included as an example of using objects.
The 'birthday' is passed in as a Date object, but it could be passed in as a string and set as a date inside the constructor.
*/