# Javascript program to enter the radius of a circle and find its diameter, circumference, and area

ADVERTISEMENTS

Javascript program to enter the radius of a circle and find its diameter, circumference, and area. There are you will learn how to find the diameter, circumference, and area of a circle in the Javascript language.

**Formula:**

*D = 2 * r*

*C = 2 * PI * r*

*A = PI * r ^{2}*

**where:**

`r`

= radius of the circle

`D`

= diameter of the circle

`C`

= circumference of the circle

`A`

= area of the circle

There are two ways to implement these formulae:

- By using the default value of PI =
**3.14** - Second, by using
**Math.PI**constant

1. By using the default value of PI = 3.14

```
/* Javascript program to find diameter, circumference, and area of a circle */
<script type="text/javascript">
var r, d, c, a;
// r = radius
// d = diameter
// c = circumference
// a = area
/* Calculation of diameter, circumference and area */
r = 10;
d = 2 * 10;
c = 2 * 3.14 * 10;
a = 3.14 * (10 * 10);
document.write("Diameter = " + d + " units<br />");
document.write("Circumference = " + c + " units<br />");
document.write("Area = " + a + " sq. units");
</script>
```

**Output Screen:**

Diameter = 20 units

Circumference = 62.800000000000004 units

Area = 314 sq. units

2. By using **Math.PI** constant

```
/* Javascript program to find diameter, circumference, and area of a circle */
<script type="text/javascript">
var r, d, c, a;
// r = radius
// d = diameter
// c = circumference
// a = area
/* Calculation of diameter, circumference and area */
r = 10;
d = 2 * 10;
c = 2 * Math.PI * 10;
a = Math.PI * (10 * 10);
document.write("Diameter = " + d + " units<br />");
document.write("Circumference = " + c + " units<br />");
document.write("Area = " + a + " sq. units");
</script>
```

**Output Screen:**

Diameter = 20 units

Circumference = 62.83185307179586 units

Area = 314.1592653589793 sq. units