programming-examples/js/Object/Calculate the area and perimeter of a circle.js
2019-11-15 12:59:38 +01:00

17 lines
440 B
JavaScript

function circle(radius)
{
this.radius = radius;
// area method
this.area = function ()
{
return Math.PI * this.radius * this.radius;
};
// perimeter method
this.perimeter = function ()
{
return 2*Math.PI*this.radius;
};
}
var c = new circle(3);
console.log('Area =', c.area().toFixed(2));
console.log('perimeter =', c.perimeter().toFixed(2));