← Back to challenges

Circle Constructor

JavaScriptHardobjectslanguage_fundamentalsgeometrymath

Instructions

Create a Circle() constructor that takes the radius as a single argument and has the following properties and methods:

  1. .radius
  2. .diameter
  3. .getC() (get circumference)
  4. .getA() (get area)

Instantiate this constructor with two circles:

  1. c1 has radius 3
  2. c2 has radius 5

For example, if I used the Circle constructor to instantiate a new instance called c0 with a radius of 1, I would have:

Examples

c0.radius ➞ 1

c0.diameter ➞ 2

c0.getC() ➞ 6.28

c0.getA() ➞ 3.14

Notes

  • Circumference: 2πr. Area: πr^2.
  • Use Math.PI for calculating circumference and area.
  • Round the perimeter and area results to the nearest hundredths place.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.