//this function will calculate a factorial
function myFactorial(n)
{
/* we assume an integer input greater than
or equal to zero */
if (n<=1) return 1;
var factorial_value=1;
var loop_index;
for (loop_index = 2; loop_index<=n; loop_index++)
{
factorial_value*=loop_index;
}
return factorial_value;
}
|
function keyword is on a separate line; argument(s) are on the same
line as the function name.
program statements are on separate lines and should be terminated with ";"
loop variable declared on a separate line using var keyword
we didn't use x or y variables since they define some properties for
dhtml objects and hence will not be scrambled.
|