MIS 3371 SPRING 2016 -- PARKS -- MIDTERM ANSWERS

This is the DIV with id="p1out"
1. (50 points) The Top 100 Downloaded Files from www.freewarefiles.com are shown to the left in a form named f1 in a textarea named ta1. For each of the 100 software downloads, the following data is shown:
   1. rank (from 1 → 100) followed by a "*"
   2. software title followed by a "*"
   3. description followed by a "*"
   4. downloads followed by a "$" (except the last one which does NOT end with a "$")
The following two arrays are defined in p1 (Do NOT write these statement):
    ms = [ "Windows" , "Microsoft" , "Internet Explorer" , "MSN" ];
    msc = [ 0 , 0 , 0 , 0 ];

Use these two arrays to search the text in column 2 and column 3. Test each field (i.e., column 2 and column 3) for the occurrence of each of the four search words in the array named ms. Count ONLY the first occurrence of each of the four search words in each cell. Use the array named msc to store the counts. NOTE: you must convert both the data AND the search terms to uppercase before making the test. Your output should be in three parts:

1. Create a 100 row, 4 column table that contains:
   1. in column 1 the rank
   2. in column 2 the software title
   3. in column 3 the software description
   4. in column 4 the download count
2. Calculate the average number of downloads for the Top 100 on a single line by itself.
3. Produce a four row-two column table that shows the four search terms in the array named ms in the first column and the count of the the number of first occurrences in the title and description fields (i.e., the counts you accumulated in the array msc).

When completed, place: (1) the 100 row 4 column table; (2) the average download count; and (3) the search words and counts table in the DIV block with id="p1out". When the user clicks the "Execute p1" button, the javascript function named "p1" is executed. Show NO HTML. Do NOT write a table heading row at the top of either table in the answer. Write only the javascript for the function p1.

 

ODD or EVEN

n =
This is the SPAN block with id="p2out"

2. (50 points) Whether a number is odd or even in javascript can be accomplished by using modular arithmetic. The modulus operator % is used to divide a number by another number and assign the integer remainder. A special case occurs when the second number is two. It allows us to decide whether of not the first number is odd or even by dividing the number by two and retaining the remainder. If the number is even the remainder will be 0. If the number is odd the remainder will be 1.

Suppose: temp = x % 2;
If x=5, then 5 % 2 has a remainder=1, then temp is assigned a value of 1 (if temp==1 then x is odd)
If x=4, then 4 % 2 has a remainder=0, then temp is assigned a value of 0 (if temp==0 then x is even)

Consider the textbox named n in a form named f2 shown on the left. You are to write the javascript function named p2() that:
1. retrieves the value of n
2. creates a table with n rows and n columns
3. each cell in the table contains one of two image files:
   If the row number is even OR the cell number is even, then the cell contains the string:
      <img src='black1x1.gif' height='15'>
   Otherwise the cell contains the string:
      <img src='white1x1.gif' height='15'>
   Assume the first row is number 0 and the first column is number 0.
4. Place the resulting table in the DIV block with id="p2out"
5. Following the table, show the percentage of table cells that have the "black1x1.gif" image.
Show NO HTML. Show only the javascript for p2.