(for answers in IE Click "View", then "Source")
Name___________________________________________ Last 4 digits PSID___________________
1. (50 points) The top 100 places to live in the US are shown in XML in the textarea to the left. The city's livability score is measured by adding up eight measures for each city (the titles for the measures are in the array titles:
var titles=["Economic","Health","Housing","Civic","Educational","Amenities","Demographics","Infrastructure"]; These measures are referred to as the tags: s1 → s8. The total of the 8 measures is the liveablity score (the tag named score below).
Data from: http://livability.com/best-places/top-100-best-places-to-live/2016/ranking-data |
|
this is the DIV with id='p1out'
| |
this is the DIV with id="p2out"
|
2. (50 points) There are 26 image files that are 30 pixels wide and 23 pixels tall. Each image is of a character of the alphabet (a → z) and the name of the image file is "t" followed by the character (a → z) and then ".gif". (e.g., the image filename for the character "a" would be "ta.gif", for the character "b" the image filename is "tb.gif", etc.).
Write the javascript function p2 that is executed when the "execute p2" button below is clicked. The function p2 performs the following actions: 1. Retrieves the textbox value shown to the left (It is named tb and is in the form is named f2 ). 2. Creates an empty string named os. 3. Creates two variables:topval and leftval and initializes both to zero. 4. Examines each character in tb. a. For each non-blank character in tb, add the image tag for the character to os: <img src='image filename' style='position:absolute;top:"+topval+"px;left:"+leftval+"px;'> Then add 30 to leftval
Show no HTML. Show only the javascript for p2 |