MIS 3371 PARKS MIDTERM FALL 2009 ANSWERS

CAUTION #1: Problem #2 requires some extra time to execute. The browser may ask you if you wish to stop running the script -- its OK to continue (i.e., the question will be "Stop running this script?" The answer is NO). It has to read the book ten times! It will finish OK.

CAUTION #2: If you print the entire source, remember you are printing a book -- so buy some more paper.

Below is texarea named t1

Below is texarea named t2

this is DIV block with id="dv1"
this is DIV block with id="dv2"
1. (50 points) At the left are two textareas, the first named t1 and the second named t2. Both appear in a form named tform. Both contain a string of words separated by commas. When the button labelled "GO" is clicked, a vbscript sub named p1 is executed. The p1 code should:
  1. retrieve the contents of the two textareas and store the strings;
  2. split each string into an array using the comma as a delimiter -- the t1 string is to be split into an array named ta1; the t2 string is to be split into an array named ta2;
  3. using EVERY word in ta1, search ta2 for exact matches;
  4. append all the words that match to an empty string named os and separate the matched words by commas;
  5. place os in the DIV block with id="dv1";
  6. count the number of matches and show the count in the DIV with id="dv2".
Note: All the words in both textareas are only lowercase; no word appears more than once in a textarea. Show NO HTML. Show only the vbscript for p1.

2. (50 points) Shown to the left is a textarea named Lewis that is in a form named Carroll. In the textarea is the entire text of Lewis Carroll's 1865 book "Alice's Adventures in Wonderland" (the text is from the Gutenburg Project). This textbox contains 147,738 bytes. There is a button labelled "GO" that when clicked executes a javscript function named p2. This function contains two 10 element arrays: (1) w; and (2) c. The array w is initialized as shown below (do not write the code shown in the box below on your exam -- just assume it is in the function).
var w  = new Array (10);
var c  = new Array (10);
w[0]="Alice";
w[1]="White Rabbit";
w[2]="Hatter";
w[3]="Queen of Hearts";
w[4]="March Hare";
w[5]="Drink Me";
w[6]="Caterpillar";
w[7]="Dormouse";
w[8]="Mock Turtle";
w[9]="Cheshire Cat";
  1. initialize the array c to zero;
  2. retrieve the text from the textarea named Lewis;
  3. for each word in the array w, search the entire book's text, determining the number of times each word occurs. Store this count for each word in the corresponding location in the array c;
  4. create a string that contains an HTML table with ten rows and two columns. In the first column of each row is a word from the array w and in the second column is the number of times this word appears in the book (i.e., in the array c);
  5. display the table in the DIV block with id="alice_out".

This is the DIV with id="alice_out"

Note 1: Be sure to convert ALL the strings to uppercase (or lowercase) before comparing.
Note 2: Use substr to extract the substrings of the book to examine.
Show NO HTML. Show only the javascript for p2.