33, Methods,


#1


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


I'm having trouble with the results, and can't understand why while I calculate the area and perimeter of a circle, the same area and perimeter returns and makes no sense. maybe because I used the area and perimeter in a previous exercise and somehow got fixed (I thought it was a new console for each exercise).
here's an example:

Radius: 10 | Area: 8 | Perimeter:12

let me first show you the code

can anybody help me? thanks in advance :slight_smile:


function Circle (radius) {
    this.radius = radius;
    this.area = function () {
        return Math.PI * this.radius * this.radius;
        
    };
    this.perimeter = function () {
        return Math.PI * this.radius * 2;
        
    };
};
var myCircle=new Circle (prompt("Radius?"))
console.log("Radius: "+myCircle.radius,"| Area: "+area,"| Perimeter:"+perimeter)


#2

I can answer myself, forgot to declare the functions; still cant understand why it worked before

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

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

};

};
var myCircle=new Circle (prompt("Radius?"))
var area= myCircle.area();
var perimeter=myCircle.perimeter();
console.log("Radius: "+myCircle.radius,"| Area: "+area,"| Perimeter:"+perimeter)


#3

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