So if you’ve been keeping up with me on my blog, then you’ll know that I’ve decided to put my development muscles to more use in my blog articles. For those of that you love my design and UX articles don’t fret, I’m still going to doing those. I just want to make a point to better show my developer side as well to the blogosphere. To start off, I’m going into Object Oriented JavaScript. YAY :)!
So, what this program below is a very primitive project management app, if you will, that I wrote early in my first few attempts at Object Oriented JS. What this code does is that it takes in a few variables passed in for a project and return some values related to the project management need of the moment. What we are going to be doing is taking it apart piece by piece first, explaining what everything does. After that we’re going to clean it up, because it is WAY to ugly for me, and add some functionality.
function Project(projName,endingAmount,totalHours,days,rate){
this.projName = projName;
this.endingAmount = endingAmount;
this.totalHours = totalHours;
this.days = days;
this.rate = rate;
this.hoursUsed = function(hours){
var hoursToday = this.hoursToday;
hoursToday += hours;
var hoursLeft = this.totalHours - hoursToday;
console.log("You've worked " + hours + "today");
console.log("You've worked " + hoursToday + " total.");
console.log("You have " + hoursleft + " remaining.");
}
this.hoursRemain = function(hours){
console.log(this.totalHours);
}
this.amountLeft = function(){
this.amountLeft = this.endingAmount - (this.hoursUsed * rate);
if(this.amountLeft > 0){
console.log(this.amountLeft);
}
else{
console.log("You workd overtime for the amount of " + Math.abs(this.amountLeft));
}
}
}