DISC 3371 Midterm Fall 2002 Parks - Answers Click View, then Source to see the code |
2. (50 points) Three gif files (named white.gif, black.gif and gray.gif) are available that are each one pixel wide an one pixel tall. An HTML page shown at the bottom left contains: (1) a textbox (size=2) named rowcount; (2) a form named dform; (3) a button with the label "Draw It". When the user enters a value in the textbox and clicks the button, a function named drawit is executed. This function contains two arrays. The arrays are named wv and gv both of size 100.
The function first checks the value in the rowcount textbox to be sure it is a number -- if not an alert box is displayed that says "You must enter a numeric value" and the function terminates. The function places into each of the first rowcount elements of the arrays wv and gv a random integer between 0 and 120 (never zero and never 120). It then creates a new page with a borderless table containing rowcount rows. Each row contains one column that is 300 pixels wide and 5 pixels tall. Each row begins with the white.gif whose height is 5 pixels and whose width is equal to the value of wv for that row. Following the white.gif on the row is gray.gif which is also 5 pixels tall and whose width is the value of gv for that row. The remainder of the row is a black.gif whose width is 300 minus the sum of the wv and gv values for that row. Following the table show the percentage (not proportion) of the table space that is white, gray and black (i.e., three numbers). An example output is shown below to the right for rowcount=21. Show only the Javascript for drawit.
|