Summary: A simple JavaScript program to manipulate class statistics.
Prerequisites: Understanding of random numbers, assignment, and strings.
Provides: An introduction to arrays and for loops.
References: Arrays and Loops in HTML
Overview:
In this exercise, we will build a simple class database in JavaScript and then analyze that database. Since it is conceptualy easiest to build an array "by hand" (assigning values to each element of the array), we will build it that way.
Build an HTML page that defines an array, class that
contains information on a sample class with five students. Each
element of the array should be a four-tuple with name, age, grade on
midterm, and grade on final, all separated by commas. For example
<script language="javascript"> var class = new Array(5) class[0] = "Jane Doe,22,80,90" class[1] = "John Doe,21,70,65" class[2] = "Jack Smith,30,80,80" class[3] = "Jen Smith,30,90,70" class[4] = "Steven Taylor,12,90,90" </script>
Write a function that, given a student number (0 through 4), returns the student's numeric grade in the class, assuming that the midterm is worth 40% of their grade and the final is worth 60%.
split() the string in the
appropriate position of the array, thereby creating a new array.
Test your function by creating a button that asks for a student number and returns the grade.
Write a function that computes the average age in the class. Make sure that it will continue to work if the class size changes.
Test your function by creating a button that responds with the average age in the class.
When students are reluctant to speak in class, I find it useful to have a page that gives me a "random" victim to call on. Write a function and corresponding button that add that functionality to your page.
This page created Wed Jun 11 14:30:25 1997 by SamR's Site Suite.