I’m supposed to declare an object literal, accepting a parameter that gets the radius of the circle. Then returns the area of the circle. Not sure how to implement the formula A = PIr^2 This is what I have so far. Am I in the right direction?
Advertisement
Answer
I am not sure why you have the a
and b
property. What is its purpose? Do you want something like this?
JavaScript
x
11
11
1
var MathUtility = {
2
getAreaOfCirlceForRadius: function(radius) {
3
return Math.PI * radius * radius;
4
},
5
getRadiusOfCircleForArea: function(area) {
6
return Math.sqrt(area / Math.PI);
7
}
8
};
9
10
console.log(MathUtility.getRadiusOfCircleForArea(12.566370614359172));
11
console.log(MathUtility.getAreaOfCirlceForRadius(2));