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.


<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) ;


Next: Example Program 4