Example Program 3

The next example of a user-defined function passes two parameters (arguments) to the function in order to calculate the area of a rectangle.

<html>
<head>

<script type='text/javascript'>

function CalcAreaOfRec(Length, Height)
{ // begin CalcAreaOfRec
var Area;

Area = Length * Height;

alert('The area of this rectangle is ' + Area);
} // end CalcAreaOfRec

// Main program
var Length ;
var Height ;

Length = prompt('What is the length?') ;
Height = prompt('What is the height?') ;

CalcAreaOfRec(Length, Height) ;

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

Next: Example Program 4