Mega Code Archive

 
Categories / JavaScript Tutorial / Math
 

Use Math round to calculate area

< html> <head> <title>A Simple Page</title> <script language="JavaScript"> <!-- function calcArea() {     inpRadius = 3;     alert(Math.round(Math.PI * ((inpRadius)*(inpRadius)))); } function calcPeri() {     inpRadius = 3;     alert(Math.round(2 * Math.PI * (inpRadius))); } function calcVol() {     inpRadius = 3;     alert(Math.round(Math.PI * ((inpRadius)*(inpRadius)*(inpRadius)) * (4/3))); } //  --> </script> </head> <body> <h1>All about Circles and Spheres!</h1> <P>Click <input type="button" value="HERE" onclick="calcArea();"> to calculate circle area!</p> <br> <P>Click <input type="button" value="HERE" onclick="calcPeri();"> to calculate circle perimeter!</p> <br> <P>Click <input type="button" value="HERE" onclick="calcVol();"> to calculate sphere volume!</p> </body> </html>