Javascript Functions

Passing Values to Functions

Functions can be given any number of values.
The important thing to observe is that the
data types in the function call correspond
to the data type in the data header.
Otherwise, an error will be generated if the
function performs a computation inappropriate for
the data type.
  
For example, if variables, x, y, and z, are passed
to function showMe(), and the function contains 
statements that assume that

   x = string
   y = number
   z = url

then the variables in the function call

   showMe(myString, myNumber, myUrl)

must correspond to the function definition in that order.
If 'myNumber' were a string and the function tried to  
multiply it, for example, the computation would be incorrect.

Example:

The code:

<script language="JavaScript">
<!--
  function showMe(x, y, z)
  {
    document.write("<h2>" + x + "</h2>");
    
    //do some math
    var result = y * 2;
    document.write("<p>You've seen this picture " + result + " times.</p>");
    
    //get a picture
    document.write("<img src=" + z + " width=\"203\" height=\"153\"><br clear=\"right\"><br />");
    return true;
    
  }
// -->
</script>

Script in <body> calls the function:

<script language="JavaScript">
<!--
  var myString = "Yet another cat picture";
  var myNumber = 67;
  var myUrl = "../images/pictures/cat2.jpg";
  
  showMe(myString, myNumber, myUrl);
// -->
</script>