Educational JavaScripting : Exercises

[Workshop] [Contents] [Experiments] [First Page] [Custom] [Quiz/Score] [Story] [Quiz/Timed] [Quiz/Math] [Stats]


Class Statistics

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:


Introduction

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 the class database

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>


Grading a student

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%.

Test your function by creating a button that asks for a student number and returns the grade.


Average age

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.


Random Victims

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.


[Workshop] [Contents] [Experiments] [First Page] [Custom] [Quiz/Score] [Story] [Quiz/Timed] [Quiz/Math] [Stats]

This page created Wed Jun 11 14:30:25 1997 by SamR's Site Suite.