More Kinds of Methods


#1

So I double checked everything but I get this error message. Oops, try again. Your method failed when sideLength was 0 where it returned NaN instead of 0. Here is my code. PLZ HELP!!!
`

var square = new Object();
square.sideLength = 6;
square.calcPerimeter = function() {
return this.sideLength * 4;
};
// help us define an area method here
square.calcArea = function() {
return this.sidelength * this.sidelength;
};

var p = square.calcPerimeter();
var a = square.calcArea();


#2

Your sideLength's in calcArea have lower case 'L's which points to a yet un initialized property making calcArea actually calculate 'undefined' * 'undefined'.


#3

thanks. I spent 20 minutes trying to figure this out!


#4

It happens. ALL THE TIME. Lol, its the worst because the writer of the code is the least likely person to see it. Keep it up!


#5

I've just started programming 17 days ago and I have been practicing everyday. It's amazing how much knowledge you can obtain in a couple weeks!


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.