- 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
Calculate difference between circumference and area of a circle - JavaScript
Circumference of a circle is given by −
pi * (r * r)
And area of a circle is given by −
2 * pi * r
Where r is the radius of the circle.
We are required to write a JavaScript function that takes in the radius of circle and calculates the difference between the area and the circumference of the circle
Example
Let’s write the code for this function −
const rad = 6; const circleDifference = radius => { const area = Math.PI * (radius * radius); const circumference = 2 * Math.PI * radius; const diff = Math.abs(area - circumference); return diff; }; console.log(circleDifference(rad)); console.log(circleDifference(5.25)); console.log(circleDifference(1));
Output
The output in the console −
75.39822368615503 53.60342465187584 3.141592653589793
Advertisements