33. Methods PLEASE HELP


#1

It keep giving me the following error and I have NO idea why....

Oops, try again. Your code caused a TypeError when trying to call .perimeter(). Make sure you have properly defined the perimeter method. Use the .area() method as a guide. Here's the error message: TypeError: c.perimeter is not a function

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

0.0


#2

Your bracket positioning is wrong

Here you need to remove one bracket

return Math.PI * this.radius * this.radius;

}
};

And here you need to add one at the end

return 2 * Math.PI * radius;
};

Your code should look like this:

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

#3

Hi,

I am confused,I don't see the difference between your code and my code but I get the error:
Oops, try again. Your code caused a TypeError when trying to call .perimeter(). Make sure you have properly defined the perimeter method. Use the .area() method as a guide. Here's the error message: TypeError: c.perimeter is not a function. (In 'c.perimeter()', 'c.perimeter' is undefined)

function Circle (radius) {
this.radius = radius;
this.area = function () {
return Math.PI * this.radius * this.radius;

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

};


#4

my bad nothing wrong with the code I just can't spell perimeter