ICE LECTURE In Class Exercises - Associative Arrays

Note: Please keep the programs that you create today, in case you have a question about your grades for the ICEs at the end of the quarter. When you're working with a partner, each person should save their own, individual copy.

ICE Part 1: Creating an associative array of simple/primitive values

Create an associative array correctly (NOT using new Array(), or anything equivalent to that) and initialize it with the names of fictitious students & their corresponding grades.  You should set up the array so that the 'index' value is the name of the student, and the value stored there is their GPA. 

Use a for ... in loop to display everything in the array on the page.

ICE Part 2: Creating and using an associative array of simple/primitive values

Make a copy of the prior exercise in order to build on it.

Put two textboxes and a button on the page.  When the user clicks the button the click handler should add the student (whose name is given by the first box) and GPA (in the second textbox) into the associative array, then display a list of students (and their GPAs) on the page somewhere.

Next, put another textbox and button on the page.  When the user clicks the button the page will check and see if the student (whose name was typed into the textbox ) is present in the array.  If so then a message listing the student's name and GPA will be displayed on the page.  Otherwise a message clarifying that the student is not present should be displayed.

ICE Part 3: Creating an associative array of objects (very, very optional)

Create a new class that will represent information about Students.  Make sure that each object will have at least 2 properties (such as name or GPA ) and at least one method (toString is fine, as long as you call it explicitly throughout the rest of this exercise)(you should add the method to the class's prototype).  If each student had only 1 property that we cared about then we could use a simple/primitive array like we did in the prior exercises.  Since each student now has multiple interesting properties we will instead use a class to package up all the interesting properties.

Next, create an associative array correctly (NOT using new Array(), or anything equivalent to that) and put some objects into it (you will need to make up values for the objects, obviously).  You should set up the array so that the 'index' value is the name of a student, and the value stored there an object representing the information about them.

Use a for ... in loop to display everything in the array on the page.

ICE Part 4: Creating and using an associative array (very, very optional :)  )

Make a copy of the prior exercise in order to build on it.

Put some textboxes and a button on the page.  When the user clicks the button the click handler should create a new Student object to represent then store that object into the associative array, then display a list of students (and their GPAs) on the page somewhere.

Next, put another textbox and button on the page.  When the user clicks the button the page will check and see if the student (whose name was typed into the textbox ) is present in the array.  If so then a message listing the student's name and interesting properties will be displayed on the page (for this you should use the toString method).  Otherwise a message clarifying that the student is not present should be displayed.