MIS 3371 FALL 2019 MIDTERM ANSWERS

1. (50 points) The data to the left is a textarea is named txt1 and is contained in a form named form1. The data is a list of the Top 100 books downloaded from the free book site Project Gutenburg on 10/3/2019. For each book the data contains:
  1. rank (from 1 to 100), followed by a "." (a period)
  2. title followed by the 4 byte string " by "
  3. author followed by a "(" character
  4. daily downloads followed by a ")" (except there is no trailing ")" for the last book)
Write the javascript function named p1 that will:
  1. retrieve the data string from txt1 and store it in a variable named bookstring.
  2. replace all the periods with a comma in the string named bookstring
  3. replace all the ocurrences of the string " by " with a "," in the string named bookstring
  4. replace all the "(" with a "," in the string named bookstring

    The resulting string (bookstring) will contain the data for the 100 books separated by the ")" character

  5. split the data in the bookstring on the ")"
  6. create a table four column 101 row table as follows:
    • The heading row has been provided for you in the string named heads and contains the headings for the first row
      [i.e., don't write the headings, just use heads]
    • in the following 100 rows place: the rank, title, author, and download count in the four cells of the row
    • Following the table, place the total number of books downloaded for the day.
  7. Place the results in the DIV block with id="p1_out"

Show only the javascript for p1.

this is the DIV block with id="p1_out"

 

MAKE A LIGHT GRAY GRID

Size

this is the DIV with id="p2_out"
2. (50 points) The data shown to the left contains a textbox named sz in a form named f2. The textbox size is two bytes. There is also a DIV block with id="p2_out"

Write the the javascript for a function named p2 that is executed when the "Execute p2" button is clicked:

  1. retrieves the value of sz from the textbox
  2. if the value of sz is even:
    1. display an alert that says "Size must be odd"
    2. set p2_out to an empty string
  3. if the value of sz is odd:
    1. produce an HTML table with sz rows and sz columns.
      if the table cell is in an odd numbered row (1,3,5,...) OR an odd numbered column (1,3,5,...) then:
      • set the cell width and height to 15 pixels
      • set the cell background to the color 'lightgray' (the attribute is 'bgcolor')
      • place a single blank in the cell
      else
      • create an empty cell
    2. place the table in the DIV with id="p2_out"
Note: if the expression: (some_number % 2) equals zero, then some_number is even

Show NO HTML. Show only the javascript for p2.