Additional question: How can I return or console.log the perimeter for a circle with radius 2?


#1



https://www.codecademy.com/en/courses/spencer-sandbox/5/4?curriculum_id=506324b3a7dffd00020bf661#

Oops, try again. It looks like you have an error in your code. Here's the message: TypeError: Cannot read property '2' of undefined
script.js

TypeError: Cannot read property '2' of undefined


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;
    };
};
console.log(Circle.perimeter['2']);


#2

you would first have to create a new instance of the object:

var a = new Circle(3);

then you can call the methods inside your object:

console.log(a.area())