====== Programming in JavaScript ====== **Adapted from**: Chapter 4 of Robert W. Sebasta, Programming the World-Wide Web, 3rd Edition, Addison Wesley, 2006. **Supporting**: [[eg-259:lecture6|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. - //Output//: A table of numbers from 5 to 15 and their squares and cubes, using alert. (See solution: [[http://jsfiddle.net/cpjobling/T4Kev/3/|on jsFiddle]]) - //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. - Modify the script of Exercise 2 to input a number, //n//, using ''prompt'', which is the number of the Fibonacci number required as output. - //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. - //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. - //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. ---- [[eg-259:homework:home|More Homework Exercises]]