Top 100 e-books downloaded last month from
https://www.gutenberg.org/browse/scores/top | 1. (50 points) The textarea (named ebooks) shown to the left contains data on the "Top 100 e-book downloads from the free book website www.gutenberg.org". The data is a form named f1. The textarea has 100 books -- each with the following data described below:
1. rank (a number from 1 → 100) followed by a period 2. book title followed by the string: " by " followed by author name CAUTION: some books have ONLY a title (i.e, there may be no " by author name" in the string) 3. the number of downloads from www.gutenburg.com last month contained in parentheses. 4.* is the last character of each book (except the last one which ends with the ")" of the download count) Create a 100 row table with four columns in each row . The columns contain: (1) rank; (2) book title; (3) author (or "unknown"); and (4) download count. Steps: 1. retrieve the data from ebooks 2. split the data from the textarea named ebooks into an array named bk using the "*" character. 3. inside the row loop, modify the value of bk[i] so that: 3a. the "." in bk[i] is replaced with a comma 3b. if bk[i] contains the string " by ", replace " by " with a comma 3c. if bk[i] does NOT contain the string " by " then replace the "(" character with the string: ",unknown(" 3d. in bk[i] replace the "(" with a comma 3e. remove the ")" character from bk[i] (i.e., replace it with an empty string) 4. bk[i] is now a string with three commas. Split this bk[i] string on the commas. 5. use the resulting four values for the cells values of the row 6. after the table display the sum of all last month's downloads 7. place the table and the download total in the the DIV with id="p1_out" NOTE: The heading for the table is stored in predefined string named headings (a pair of row tags and 4 cell tag pairs containing column descriptions). Use headings to place headings at the top of the table (but DO NOT write out this string in your code).
When the button to the left is clicked, a javascript function named p1 is executed.
This is the DIV block with id="p1_out"
|
Largest 1,000 USA Cities | 2. (50 points) The textarea named ta2 shown to the left contains the largest 1,000 cities in the USA. The data is contained in a form named f2.Each city has:
1. a rank followed by a semicolon 2. city name followed by a semicolon 4. state name followed by a semicolon 3. population followed by a semicolon 5. percent population change in the last 10 years followed by the "@" symbol (except for the last one which ends in a "%") Assume there is an 51 element array named sn that contains the 50 state names and the "District of Columbia" (the array is in alphabetic order). Assume there are four more arrays each with 51 elements: They are named meg; halfmeg; hundredk and small. Assume these 51 elements of these four arrays have been initialized to zero. Assume there is prefined string named headings that stores the heading string for the the 5 table columns. Write the javascript function named p2 that makes a 51 row table (not counting the headings) with 5 columns and place it in the DIV block with id="p2_out". The 5 columns contain: 1. a value of sn (i.e., column 1 shows the 50 state names and "District of Columbia" in alphabetic order) 2. the number of cities in this state of sn with population >= 1,000,000 use the array named meg to store these counts 3. the number of cities in this state of sn with population >= 500,000 and < 1,000,000 use the array named halfmeg to store these counts 4. the number of cities in this state of sn with population >= 100,000 and < 500,000 use the array named hundredk to store these counts 5. the number of cities in this state of sn with population < 100,000 use the array named small to store these counts You will need to; 1. get the data from the textbox ta2; 2. split it into 1,000 cities; and 3. for each city: find the location (row number) of the state name (or "District of Columbia") in the sn array if the population is >= 1,000,000, add 1 to the corresponding location in meg if the population is >= 500,000 and < 1,000,000, add 1 to the corresponding location in halfmeg if the population is >= 100,000 and < 500,000, add 1 to the corresponding location in hundredk if the population is < 100,000, add 1 to the corresponding location in small When the button to the left is clicked, a javascript function named p2 is executed. Show only the javascript for p2(). Show NO HTML. This is the DIV block with id="p2_out"
|