The Math object is particularly useful for creating online demonstrations. Here we use the Math object to determine properties of a circle and sphere given the radius, displaying the results on a clear page.
<form name="mathForm"> <input type="button" value="Go!" onClick="goForIt()"> </form>
<script language="JavaScript"><!--
function goForIt(){
text1=prompt('Enter the desired radius below','5'); //prompts the user for a number
var radius=parseFloat(text1); //interpret the input string as an integer
var circ=Math.PI*radius*2; //calculate circumference
var area=Math.PI*Math.pow(radius,3); //calculate area
var vol=Math.PI*Math.pow(radius,3)*4/3; //calculate volume
var textToDisplay='For a radius '+ radius +'cm:<br>';
textToDisplay+='The circumference of the circle is '+ circ +'cm<br>'; //concatenating strings...
textToDisplay+='The area of the circle is '+ area +'square cm<br>'; //makes it much easier
textToDisplay+='The volume of the sphere is '+ vol +'cubic cm<br>'; //to read your script
document.write(textToDisplay); //displays output, clearing the current page in the process
}
// --></script>