Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Post Top Ad

Your Ad Spot

Monday, January 16, 2023

Area and Circumference of Circle Using javascript


Area and Circumference of Circle Using javascript




In this article, we are going to learn how to calculate the area and circumference of a circle using javascript. In this program, we are going to use prompt () to input data and calculate area and circumference without using function and event.

 

Area and Circumference of Circle Using javascript


Formula:


Area=PI X radius X radius


Circumference=2 X PI X radius


Note: In the Greek letter PI (Ï€) represents a constant, approximately equal to 3.14159. The result will display in the floating point.




Source Code:

 

Area and Circumference of Circle Using javascript


Explanation:



In the above program, we input the data with the help of prompt() and the value is stored in the variable radius. parseInt function converts the input data into numbers.


Now, we calculate the area of the circle using the formula π * r^2 and the circumference of the circle using the formula 2 * π * r where, π is the value of pi (approximately 3.14) and r is the radius of the circle. After calculating the area and circumference stored in the variable area and cir respectively.

Now, document.write() statement display the output on the page.


Output:

 

Area and Circumference of Circle Using javascript



Final Words:

I hope you understood how to calculate the Area and Circumference of Circle Using javascript. In the next article, we are going to solve the same problem by using functions and buttons. If you have any suggestions, please feel me to write it comment box.


You may also like:

if..else if..else statement in JavaScript

if..else Statement in JavaScript

if statement in JavaScript


No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages