33 Methods. Code isnt working...?


#1


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

i dunno whats the issue here please help? feel like im forgetting to call a function


#2

updated code.

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

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

var circle = new Object("Circle");
var area = circle.radius;
var perimeter = circle.perimeter;

still doesnt seem to work.... :frowning:


#3

First you create a variable holding the new Circle.

var MyCircle = new Circle(40);

Then you can use the methods that MyCircle inherits from the Circle constructor.

console.log(MyCircle.area());

#4

If we know the radius then.......

Perimeter (P) = 2 · π · R
where:
R is the radius of the circle
π is Pi, approximately 3.142

and here

var circle = new Object("Circle");

what are you trying to do?you have to use Circle constructor here

go to previous lessons and check how to create a new Object using constructor


#5

yeah i dunno. this part and the last stumped me. i fluked the previous lesson


#6

Try reading this https://css-tricks.com/understanding-javascript-constructors/ . Since it is on CSS-Tricks and has been reviewed by Kyle Simpson I would trust what is saying :slight_smile: .

(Also, the perimeter change that rcodeman suggested would be a good idea)


#7

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