the
1st line specifies that we are defining a
function named FahrToCelsius that takes one
input
nthe variable name in parentheses is known as a parameter
nwhen the function is called, the provided input is
assigned to the parameter
pe.g., for the call FahrToCelsius(32), the value 32
would be assigned to tempInFahr for the
calculation
function
FahrToCelsius(tempInFahr)
// Assumes:
tempInFahr is a temperature in Fahrenheit
// Returns:
the equivalent temperature in Celsius
{
return (5/9) * (tempInFahr - 32);
}
the 2nd and 3rd lines are comments that
describe the behavior of the function
nanything
to the right of // is ignored by the browser (so not strictly
required)
nbut,
you should ALWAYS have comments in any user-defined function to make the code
easier for the human to read
and understand
the actual code that carries out the function's
computation is enclosed in { }
nhere,
the function definition contains only one statement, but there could be
more
na
return statement specifies the value that should be returned by the function (i.e., it's output)