MIS 3371 MIDTERM ANSWERS FALL 2018 PARKS
1. (50 points) The 'Top 100 Retailers for 2018' are shown in the textarea to the left (data from here). The textarea is named ta1 which is in a form named f1. For each company the following data is provided:

     1. rank in 2018 (followed by a semicolon)
     2. company name (followed by a semicolon)
     3. 2017 sales (in billions; contains a decimal point; is followed by a semicolon)
     4. headquarters location (followed by a semicolon)
     5. number of retail stores (is followed by a # sign -- except the last one)

Write the javascript function named p1() that:

   1. retrieves the company data from the textarea.
   2. creates a 100 row by 5 column table showing the data for each company
      Assume the column heading row is stored in a string named heading
      DO NOT write the HTML code for this heading -- just use it
   3. find the company with the largest number of stores
      When a new maximum is found, also store the company name
      If company's number of stores value = "N.A." skip the store count comparison.
   4. calculate the average company sales
   5. place in the SPAN block with id="p1_out":
      (a) the 100 x 5 table (with the heading provided)
      (b) the average retail sales value for all the 100 companies
      (c) the company name with the most stores and the number of stores.

Show only the javascript for p1.

this is the p1_out SPAN block

1. 1st Color→
DarkRed

DarkBlue

DarkGreen
2. 2nd Color →
White

Gray

Black
3. Square Size in pixels
4. Number of rows/columns

this is the SPAN with id="p2_out"

2. (50 points) The HTML elements shown to the left allow the user to create a square checkerboard pattern by choosing: two colors; a square size; and the number of rows/cols. This HTML is in a form named f2. The checkerboard is created by making an HTML table where each table cell has: a height; a width; and background color specified. The background colors of the table cells alternate to produce the checkerboard pattern.
  1. The first three radio buttons allow the user to choose the 1st color. Test for which element is checked (document.f2.elements[0].checked through document.f2.elements[2].checked). Use the chosen color as the 1st color (the values for the elements are: "DarkRed", "DarkGreen" or "DarkBlue", respectively).
  2. The second three radio buttons allow the user to choose the 2nd color. Test for which element is checked (document.f2.elements[3].checked through document.f2.elements[5].checked). Use the chosen color as the 2nd color (the values for the elements are: "White", "Gray" or "Black", respectively).
  3. The textbox for the size of the square is named sz
  4. The textbox for the row/column count is named rc [Note: same number of rows as columns]
  5. Create a table with rc rows and rc columns.
    Each table cell will have the format:

        <td width='square size' height='square size' bgcolor='some color'> </td>

    Even numbered rows start with the 1st color, Odd numbered rows start with the 2nd color. Use a variable named color_switch to store a zero for the 1st color OR a one for the 2nd color. Set the value of this switch at the beginning of each row, then alternate the color as each additional table cell in the row is produced

  6. Place the resulting HTML table in the SPAN block with id="p2_out"
Note: assume the first row and first column are numbered as zero.
Note: each cell contains a single blank character.
Show NO HTML. Show only the javascript for p2.