Chapter 9

Question 9.1

  1. a) functions
  2. b) function call
  3. c) local variable
  4. d) return
  5. e) function.

Question 9.2

  1. a) global scope.
  2. b) function scope.
  3. c) global scope.
  4. d) global scope.

Question 9.3

  1. a) Global.
  2. b) isNaN.
  3. c) escape.
  4. d) eval.
  5. e) unescape.

Question 9.4

  1. a) scope.
  2. b) return; or return expression; or encountering the closing right brace of a function.
  3. c) Math.random.
  4. d) local.

Question 9.5

  1. a) Error: method is not the keyword used to begin a function definition. Correction: Change method to function.
  2. 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;
  3. 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