Chapter 9
Question 9.1
- a) functions
- b) function call
- c) local variable
- d) return
- e) function.
Question 9.2
- a) global scope.
- b) function scope.
- c) global scope.
- d) global scope.
Question 9.3
- a) Global.
- b) isNaN.
- c) escape.
- d) eval.
- e) unescape.
Question 9.4
- a) scope.
- b) return; or return expression; or encountering the closing right brace of a function.
- c) Math.random.
- d) local.
Question 9.5
- a) Error: method is not the keyword used to begin a function definition.
Correction: Change method to function.
- b) Error: The function is supposed to return a value, but does not.
Correction: Either delete variable result and place the statement return x + y;
in the function or add the following statement at the end of the function body: return result;
- c) Error: The semicolon after the right parenthesis that encloses the parameter list.
Correction: Delete the semicolon after the right parenthesis of the parameter list.
Question 9.6
Write a complete JavaScript program to prompt the user for the radius of a sphere, then call function sphereVolume to calculate and display the volume of the sphere. Use the statement
volume = ( 4.0 / 3.0 ) * Math.PI * Math.pow( radius, 3 );
Question 9.6
Question 9.7
Write a script that uses a form to get the radius of a circle from the user, then calls the function circleArea to calculate the area of the circle and display the result in a paragraph on the page. To get the number from the form, use the techniques shown in Self-Review Exercise 9.6.
Java 9.7 answer
Question 9.8
Java 9.8 answer