How to call it?


#1

How to call these functions below? Owing to this code it shows me only [Function] [Function], but a purpose is to make it calculate. Thanks for tips.


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 Math.PI * 2 * this.radius
    }
};

var calc = new Circle(10);
console.log(calc.area, calc.perimeter);


#2

methods are just like functions (in a way), they require parentheses when called:

calc.area()

in the parentheses you need to supply arguments if needs be, but this is not necessary in this case, your methods don't have parameters


#3

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