- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to calculate the area and perimeter of a circle in JavaScript?
To calculate the area and perimeter of a circle, you can try to run the following code −
Example
<html> <head> <title>JavaScript Example</title> </head> <body> <script> function Calculate(r) { this.r = r; this.perimeter = function () { return 2*Math.PI*this.r; }; this.area = function () { return Math.PI * this.r * this.r; }; } var calc = new Calculate(5); document.write("Area of Circle = ", calc.area().toFixed(2)); document.write("<br>Perimeter of Circle = ", calc.perimeter().toFixed(2)); </script> </body> </html>
Advertisements