Part 33. Methods


#1

function Circle (radius) {
this.radius = radius;
this.area = function () {
return Math.PI * this.radius * this.radius;
}
};
// define a perimeter method here
function Circle (perimeter) {
this.perimeter = perimeter;
this.perimeter = function() {
return Math.PI * 2 * this.radius;
}
};

I have no clue what I'm doing. I'm not even getting a number back so could someone point me in the right direction? Also heres the error code if it helps.
Oops, try again.
Your perimeter method fails on a Circle with radius 1 where it returns NaN when it should return 6.283185307179586


#2

Notice how this method is written inside the object literal code body? That is where the perimater() method should be as well. It can be fashioned almost exactly like the area() method above.

    this.area = function () {
        return Math.PI * this.radius * this.radius;
    };
    // the semi-colon is an important part of JS syntax
    this.perimeter = function () {
        return // your code
    };

When you're done, you'll want to test it.

circle = new Circle(5);
circle.area();
circle.perimeter();