


















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



















































22 // The following square function's body is executed 23 // only when the function is explicitly called. 24 25 // square function definition 26 function square( y ) 27 { 28 return y * y; 29 } 30 // --> 31 32 33 34
SquareInt.html (2 of 2)
Variable y gets the value of variable x.
The return statement passes the value of y * y back to the calling function.
1 2 4 5 6 7 8 9 10 Finding the Maximum of Three Values 11 12 24 25 var maxValue = maximum( value1, value2, value3 ); 26 27 document.writeln( "First number: " + value1 + 28 "Second number: " + value2 + 29 "Third number: " + value3 + 30 "Maximum is: " + maxValue ); 31 32 // maximum method definition (called from line 25) 33 function maximum( x, y, z ) 34 { 35 return Math.max( x, Math.max( y, z ) ); 36 } 37 // --> 38 39 40 41 42
Click Refresh (or Reload) to run the script again
43 44Maximum.html (2 of 2)
Call function maximum and pass it the value of variables value1, value2 and value3.
Variables x, y and z get the value of variables value1, value2 and value3, respectively.
Method max returns the larger of the two integers passed to it.