Example Program 2

This code in the previous example program could be modified so that it is the user who decides what value is to be used as the radius. The function will stay exactly as it is but the following code could be added before the call to the function:

<html>
<head>

<script type='text/javascript'>

function CalcAreaOfCircle(Radius)
{ // begin CalcAreaOfCircle
var Area ;

Area = Radius * Radius * 3.14 ;

alert ('The area of this circle = ' + Area) ;
} // end CalcAreaOfCircle

// Main program
var Radius ;

Radius = prompt('What is the radius of the circle?');

CalcAreaOfCircle(Radius);

</script>
</head>
<body>
</body>
</html>

Next: Example Program 3