User Tools

Site Tools


eg-259:homework:8

Programming in JavaScript

Adapted from: Chapter 4 of Robert W. Sebasta, Programming the World-Wide Web, 3rd Edition, Addison Wesley, 2006. Supporting: Contact Hour 8.

Exercises from the Lecture

Write, test and debug (if necessary) XHTML files that include JavaScript scripts for the following problems. When required to write functions, you must include a script to test the function with at least two different data sets.

  1. Output: A table of numbers from 5 to 15 and their squares and cubes, using alert. (See solution: on jsFiddle)
  2. Output: The first 20 Fibonacci numbers, which are defined as in the following sequence 1, 1, 2, 3, … where each number in the sequence is the sum of the two previous numbers. Use document.write to produce the output.
  3. Modify the script of Exercise 2 to input a number, n, using prompt, which is the number of the Fibonacci number required as output.
  4. Function: no_zeros; Parameter: An array of numbers; Result: The array must be modified to remove all zero values. Returns: true if the given array included zeros; false otherwise.

Additional Exercises

Try these additional exercises if you need more challenges. They are also from Chapter 4 of Sebasta.

  1. Function: counter; Parameter: An array of numbers; Returns: The numbers of negative elements, zeros, and values greater zero in the given array. Note: You must use a switch statement in the function.
  2. Function: row_averages; Parameter: An array of arrays of numbers. Results: An array of the averages of each of the rows of the given matrix.

More Homework Exercises

eg-259/homework/8.txt · Last modified: 2013/02/15 12:54 by eechris