THE ALAMO DEFENDERS
|
2. (50 points) The list of the 193 known defenders of the Alamo (e.g., see this) is shown in a textarea named ta to the left. This textarea is in a form named f2. When the button labeled "GO" at the botton of the textarea is clicked the javascript function p2( ) is executed. The textarea ta contains for each of the 193 defenders their:
- Last Name followed by a comma
- First and Middle Name(s) followed by a comma
- Place of Birth followed by a comma
So there are 193 entries -- each with 3 commas. There are exactly 30 different birth places in this list. The names of these thirty birthplaces are stored in an array named bp, (e.g., bp[0]="Texas", bp[1]="Virginia"; bp[2]="Vermont", etc.). The bp array is available in the function p2. (Do not write or create the contents of the array bp -- assume it is already in the function and all thirty values have been defined). The javascript function p2 should:
- retrieve the contents of the textarea ta and store it in a string named a.
- split the string a using the comma into an array named n -- there will be 579 elements in n (i.e., 3 times 193).
- create another array named bpcount that has 30 elements -- these 30 elements will be used to count the number of occurences of each birthplace in the array n.
- initialize the elements of the array bpcount to zero.
- loop through the array n examining only the birthplace elements
(i.e., every third element -- n[2], n[5], n[8], n[11],...etc.)
- find each birthplace in the bp array and increment the corresponding location in bpcount by 1.
(i.e., for each birthplace n[2], n[5], n[7], etc., search through the entire bp array and find the location of the birthplace in bp, then add 1 to the corrsponding location in bpcount
- In the DIV block with id="z" (shown below) write:
(a) the 30 birthplaces (bp) and counts (bpcount) (separated by a <br> tag)
(b) the birthplace with the largest count
This is the DIV block with id="z"
Show NO HTML. Show ONLY the javascript code for p2.
|