Area and Circumference of a Circle
Given radius
radius of a circle, write a JS constructor function with the methods getArea and getCircumference to calculate the area and circumference of the circle.
Note
The value of π = 3.14
Quick Tip
Use the formulae to calculate,
Area of circle = π * radius * radius
Circumference of circle = 2 * π * radius
Input
The input will be a single line containing a number radius
Output
The first line of output should contain the area of the circle
The second line of output should contain the circumference of the circle
Sample Input 1
7
Sample Output 1
153.86
43.96
Sample Input 2
25
Sample Output 2
1962.5
157
function AreaCircumference(radius) {
this.radius = radius;
this.getArea = () => 3.14 * this.radius ** 2;
this.getCircumference = () => 2 * 3.14 * this.radius;
console.log(this.getArea());
console.log(this.getCircumference());
}
const radius1 = new AreaCircumference(7);
const radius2 = new AreaCircumference(25
Comments
Leave a comment