# Area and Circumference of Circle Using TypeScript

## Introduction

Today I am going to explain how to calculate the area and circumference of a circle using a class in TypeScript. Using this we can perform other types of calculations and generate the results. The area of the circle can be calculated by multiplying the Pi value that is 3.14 by the square of the radius of the circle, and the circumference can be calculated by multiplying the radius by Pi and 2.

Circumference of Circle = 2 * 3.14 * Radius

Now in order to see how it works let's use the following steps.

Step 1

Open Visual Studio 2012 and click on "File" -> "New" -> "Project...".

Step 2

A window is opened; in it click HTML Application for TypeScript under Visual C# and give the name of your application then click ok.

Step 3

Write the following TypeScript code in the app.ts file:
1. class Circle {
5.  }
6.  AreaOfCircle() {
8.  }
9.  CircumferenceOfCircle() {
10.   return 2 * 3.14 * this.Radius;
11.  }
12. }
13. var circle = new Circle(5);
14. var area = circle.AreaOfCircle();
15. var circumference = circle.CircumferenceOfCircle();
16. alert("The Area of the Circle is :" + area);
17. alert("The circumference of the Circle is :" + circumference);
Step 4

Write the following JavaScript code in the app.js file:
1. var Circle = (function() {
4.  }
5.  Circle.prototype.AreaOfCircle = function() {
7.  };
8.  Circle.prototype.CircumferenceOfCircle = function() {
9.   return 2 * 3.14 * this.Radius;
10.  };
11.  return Circle;
12. })();
13. var circle = new Circle(5);
14. var area = circle.AreaOfCircle();
15. var circumference = circle.CircumferenceOfCircle();
16. alert("The Area of the Circle is :" + area);
17. alert("The circumference of the Circle is :" + circumference);
Step 5

Open the default.htm file and write the code as:
1. <!DOCTYPE html>
2. <html lang="en"
3.     xmlns="http://www.w3.org/1999/xhtml">
5.         <meta charset="utf-8" />
6.         <title>TypeScript HTML App</title>
7.         <link rel="stylesheet" href="app.css" type="text/css" />
9.     <body>
10.         <h1>Circle Function</h1>
11.         <div id="content">
12.             <script src="app.js"></script>
13.         </div>
14.     </body>
15. </html>
Step 6

Now run the application and the output will look like:

Summary

In this article, I explained how to find the area and circumference of the circle using a class in TypeScript.