MIS 3371 MIDTERM & ANSWERS FALL 2016 PARKS

1. (50 points) The textarea to the right is named ta1 is in a form named f1 The data contained in ta1 is the Top 100 US Newspapers. Three items of data for each newspaper is provided:

1. rank followed by a semicolon
2. newspaper name (city, state) followed by a semicolon
    (NOTE: some state values are missing)
3. circulation followed by a question mark
    (except the last one which does not have a "?" at the end)

Write the javascript function p1 that:
1. Retrieves the data from ta1.
2. Produces a 100 row by 4 column table that contains in the 4 columns:
   1. rank
   2. newspaper name
   3. city state [be sure the parenthesis have been removed]
   4. circulation
3. Assume there are two 14 element arrays:
   var title_word = ["Chronicle","Daily","Dispatch","Enquirer","Gazette","Herald","Journal",
                               "News","Post","Press","Register","Sentinel","Times","Tribune"];
   var tcount = [0,0,0,0,0,0,0,0,0,0,0,0,0,0];
4. Count the number of times each title_word appears in the 100 newspaper names.
   Store the 14 counts in the array named tcount.
   DO NOT WRITE these two arrays. Assume there are in p1
5. Additionally follow the table with 14 lines each containing title_word and its count
6. Place the table and the title_words/counts in the DIV with id="p1_out"

Show only the javascript for p1.

this is the p1_out DIV

Bar Graph Color:


blue
red
green
yellow
black

Max. Height (pixels)

2. (50 points) The object of the javascript function p2 is to create a vertical bar graph for the grades on an examination. Assume there are two arrays in p2 defined as follows:
      var grades = [8,13,17,23,35,21,16,12,5,1];
which represents the number of grades for an exam in each of 10 intervals: 90-100, 80-89,...0-9.
      var image_name = ["blue1x1.gif","red1x1.gif","green1x1.gif", "yellow1x1.gif","black1x1.gif"];
which represents the names of five possible gif images used to construct the bar graph.
DO NOT Write the arrays, assume they exist in p2
The form shown to the left is named f2. There are five radio buttons that allows the user to choose the color of the bar graph. The 'value' of the first radio button is "0", the value of the second is "1", ... , and the value of the fifth is "4". The radio buttons do not have names (use the elements[0], elements[1], ... to refer to the element).
The textbox shown to the left is named maxh and contains the maximum height of the tallest bar in the data above. You are to create a vertical bar graph of these 10 values as follows:
1. Retrieve the color value chosen by the user (0,1,2,3 or 4)
2. Retrieve the maximum bar graph height
3. Find the largest (maximum) frequency in the array named grades
    Store this value in a variable named maxg
4. Create a two row by ten column table. The table should have the attribute: border='0'
    a. each table cell of the first row should have the attribute: valign='bottom'
    b. each table cell of the first row will contain a single image tag
        the image name from the array named image_name depends on the value of the checked radio button.
        the image width: width='20'
        the image height will be calcuated by: grades[i] / maxg * maxh
    c. each table cell of the second row will contain the value of grades[i] and have attribute align='right'
5. Place the resulting table in the DIV with id="p2_out"
Show NO HTML. Show only the javascript for p2.

+

this is the DIV with id="p2_out"