In this example we will calculate area and circumference of the circle according to given radius. we use the following mathematical formula for calculating area and circumference of the circle In JavaScript:
Area of Circle= radius * radius * PI
circumference of the circle = 2 * radius * PI

Where radius is the radius of the circle and PI is the constant value of the pi.
<html> <head> <title>Find the area and circumference of a circle</title> </head> <body> <script language="JavaScript"> function CalculateArea(){ var radius =document.form1.txtRadius.value; document.write("<P>The area of the circle is " + (radius * radius * Math.PI) + "</p>"); document.write("<P>The circumference of the circle is " + (2 * radius * Math.PI) + "</p>"); } </script> <form name=form1> Enter the radius of circle: <input type="text" name="txtRadius" size=10> <br> <input type="button" value="Calculate" onClick='CalculateArea();'> </form> </script> </body> </html>
not working
hi Thanks
I have corrected the code..Actually i have just uncommented function ‘CalculateArea’…
now please try