JavaScript Math Object Lab
Easy
26
1
73.3% Acceptance
In this lab, the primary objective is to understand and implement functions that perform geometric calculations related to circles. Specifically, participants will be tasked with creating two functions: calcCircumference
and calcArea
. Each function leverages the mathematical constant π (Pi), reflecting the relationship between the diameter (or radius) of a circle and its circumference and area respectively.
Function Objectives:
-
calcCircumference(radius)
:- This function should calculate the circumference of a circle.
- The formula to calculate circumference
C
isC = 2πr
, wherer
is the radius of the circle. - The function takes one argument,
radius
, which represents the radius of the circle. - It returns the calculated circumference as a numeric value.
-
calcArea(radius)
:- This function should calculate the area of a circle.
- The formula to calculate area
A
isA = πr^2
, wherer
is the radius of the circle. - Similar to
calcCircumference
, this function takes one argument,radius
. - It returns the calculated area as a numeric value.
Steps to Implement:
-
Write the Function
calcCircumference
:- Start by declaring the function using the keyword
function
. - Name the function
calcCircumference
and ensure it accepts one parameter,radius
. - Inside the function, use the
Math.PI
constant to calculate the circumference. - Return the result.
- Start by declaring the function using the keyword
-
Write the Function
calcArea
:- Declare another function named
calcArea
. - Accept
radius
as the parameter for this function as well. - Calculate the area using
Math.PI
&Math.pow
functions. - Return the result of the calculation.
- Declare another function named
-
Export the Functions:
- Both functions should be individually exportable and usable in other modules.
- Use the ECMAScript module (ESM) syntax for exporting.
calcCircumference()
should be named export using theexport
keyword whilecalcArea
function should be a default export using theexport default
keywords.