Methods


#1



Hey guys, so I don't know what I did wrong here...
The goal was to create a method called perimeter that calculated the perimeter. It already gave me the radius as an example. The error message was:
Oops, try again. Your perimeter method fails on a Circle with radius 1 where it returns NaN when it should return 6.283185307179586

Can you guys help me with this? Thanks!


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;
        }  
};


#2

You could start with only defining things once, right? Remove the redundant code.

I also suggest keeping indentation consistent with your braces, so it's easier to tell what belongs to what.

For debugging, you can use console.log's to print out what it is doing step by step, that might tell you where things go wrong.


#3

Ok, I got it, yeah, I removed the part where it said
function Circle (perimeter) {
this.perimeter = perimeter;

and it worked. Thanks!