简体   繁体   中英

javascript object literals — formula

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?

I am not sure why you have the a and b property. What is its purpose? Do you want something like this?

 var MathUtility = { getAreaOfCirlceForRadius: function(radius) { return Math.PI * radius * radius; }, getRadiusOfCircleForArea: function(area) { return Math.sqrt(area / Math.PI); } }; console.log(MathUtility.getRadiusOfCircleForArea(12.566370614359172)); console.log(MathUtility.getAreaOfCirlceForRadius(2));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM