简体   繁体   English

javascript object 文字 — 公式

[英]javascript object literals — formula

I'm supposed to declare an object literal, accepting a parameter that gets the radius of the circle.我应该声明一个 object 文字,接受一个获取圆半径的参数。 Then returns the area of the circle.然后返回圆的面积。 Not sure how to implement the formula A = PIr^2 This is what I have so far.不知道如何实现公式 A = PIr^2 这是我到目前为止所拥有的。 Am I in the right direction?我在正确的方向吗?

I am not sure why you have the a and b property.我不确定你为什么拥有ab属性。 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));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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