Methods


#1

I need help with this exercise i don't understand good

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

Define a method perimeter that calculates the perimeter of a circle.

help me please


#2

look at your area method, it has very different (and the right) syntax. Please correct your perimeter method using the area method as blue print


#3

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

};

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

};

}
i make mi code again ,it's correct or not?
because i have the confution with the relation :frowning:


#4

what did you do? i said that the syntax of your perimeter method was incorrect, and you should look at the area method for correct syntax, and you did something completely different?


#5

and this, sorry im very very bad with this :frowning:

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

};

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

};
};
perimeter(4)

#6

Your code

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

Everything was fine until I saw this --

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

Lets read what the problem says us to do..

Define a method perimeter that calculates the perimeter of a circle.

When we add a method to a constructor we use this keyword and attach (dot notation) with methods name ( same as variables) .

suppose if this constructor needs a method that returns name of coder who wrote it.
I'd write something like this.

// define a method that gives coders name
   this.coder = function(){
        return "santiago.rodriguez"
        }

Do you get the hint?
I hope it helps!! :slight_smile:


#7

omg i understand a lot with your help thanks you at the end this is my code,and the moderator doesn't explain me but if your don't help me .i can't resolve this thank you very much

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

};
this.perimeter = function () {
    return 2*(Math.PI) * this.radius;

};
console.log(this.perimeter(1))
// define a perimeter method here

};


#8

Youre welcome! :slight_smile:
Actually, Because of Mod I was able to see this thread (post).
Kudos to mod :thumbsup: and I'm glad it worked !:slight_smile:


#9

ok thanks mod jajaja


#10

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