33. Methods - Why the code doesn't print circle's perimeter?


#1


https://www.codecademy.com/courses/spencer-sandbox/5/4?curriculum_id=506324b3a7dffd00020bf661
Introduction to Objects
33. Methods


The code prints "[function]" instead of the circle's perimeter. Why?


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

    
var circle1 = new Circle(5);
console.log(circle1.perimeter)


#2

What you are seeing is the object class, [Function] which is what gets returned when we poll the function identifier like a variable. To run a function, we invoke it with ()

console.log(circle1.perimeter());

#3

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