JSFiddle - React, Tailwind, and code Playground
by Karl Hui
JavaScript
//Assignments 1 & 2
//Karl Hui
//May 29 2014
// defines that this is a class with the parameters of month and day
function Birthday(month, day){
this.month = month;
this.day = day;
}
// defines the variables within the class. the way of seeing it is class.prototype.parameter = default variable
Birthday.prototype.month = 0;
Birthday.prototype.day = 0;
//These are the functions that will be called later on to compare the birthday and the dates
Birthday.prototype.compareDates = function(anyDay){
if (this.month == anyDay.month && this.day == anyDay.day){
return true;
}
else{
return false;
}
};
Birthday.prototype.compareToToday = function(){
var today = new Date();
return this.compareDates(Today);
};
//This asks for prompts that will be used later on.
var userMonth = prompt("Enter the birthday month.");
if (userMonth == "January"){
userMonth = 0;
}
else if (userMonth == "February"){
userMonth = 1;
}
else if (userMonth == "March"){
userMonth = 2;
}
else if (userMonth == "April"){
userMonth = 3;
}
else if (userMonth == "May"){
userMonth = 4;
}
else if (userMonth == "June"){
userMonth = 5;
}
else if (userMonth == "July"){
userMonth = 6;
}
else if (userMonth == "August"){
userMonth = 7;
}
else if (userMonth == "September"){
userMonth = 8;
}
else if (userMonth == "October"){
userMonth = 9;
}
else if (userMonth == "November"){
userMonth = 10;
}
else if (userMonth == "December"){
userMonth = 11;
}
else if (userMonth >= 1 && userMonth <= 12){
userMonth = userMonth-1;
}
else{
alert("Your input is invalid.");
}
var userDay = prompt("Enter the birthday day.");
if (userDay >= 1 && userDay <= 31){
}
else{
alert("Your input is invalid.");
...