CISC103, Fall 2007

First Midterm Exam (E02)

November 8, 2007

Name: ________________________________________________________________


UD Email: _____________________________________________@ udel.edu


Do not write your name on any page except this one.

Answer all questions on this paper directly.

Total Points: ???


A hint about allocating your time:

You need to answer 100 points worth of questions in 75 minutes, so....

That will allow you to complete 100 points worth of questions in 50 minutes.
Then you'll have 25 minutes left over so that you can either


Refer to the handout to answer these questions.

  1. Here is the code for the web page shown on the handout, but with several parts missing.
    Fill them in according to the instructions given in the bold comments.
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Purchase Tickets</title> <style type="text/css"> /* (a) (5 pts) write a line of CSS that says that all p elements of class buttonParagraph should be centered. Use the property text-align and the property value center */ </style> <script type="text/javascript" src="ticketCalc.js"></script> <script type="text/javascript"> function calculateTotalCharge() { // (b) (9 pts) Complete the incomplete statements by filling in the // actual parameter of the getElementById call // // Set up three variables to store the objects that represent // the input boxes on the screen var studTicketsElem = window.document.getElementById( ); var otherTicketsElem = window.document.getElementById( ); var priceElem = window.document.getElementById( ); // (c) (10 pts) Complete the right hand side // of the assignment statements. // Set up two variables to represent the total number of each type // of ticket that the user wants to order. Note: you can't order // "half" a ticket, or 1.7 tickets---it must be a whole number. var numStudentTkts = var numOtherTkts = // (d) (10 pts) Complete the right hand side // of the assignment statement // Use the function ticketCalc() to determine the total price var totalPrice = // (e) (10 pts) Complete the left hand side // of the assignment statement. // Put the result totalPrice on the screen for the user to see = totalPrice; } </script> </head> ... (continued in next box)

    HTML page continued...

      ... (continued from previous box)
    <body>
    
    <h1>Jon Stewart Tickets</h1>
    
    <!-- (e)  (6 pts)  Fill in the HTML open tag that needs 
         to be here because <input ... > elements are present.
    
         Hint: it needs the attribute action="" to validate properly,
         so don't forget to add that.       -->
    
    
    
    
    <table>
    <tr>
      <th>Student Tickets ($ 30 each)</th>
      <td><input type="text" size="10" id="stBox" name="stBox" /></td>
    </tr>
    <tr>
      <th>Other Tickets ($65 each)</th>
      <td><input type="text" size="10" id="otBox" name="otBox" /></td>
    </tr>
    <tr>
      <th>Total Price: </th>
      <td>
        <input type="text" size="10" 
                     id="priceBox" name="priceBox" readonly="readonly"/>
      </td>
    </tr>
    </table>
    
    <!-- (f) (6 pts) Fill in the missing code
    
         Make it so that the appropriate JavaScript function 
         is called when when the button is pressed               -->
    
    <p class="buttonParagraph">
    
    <input type="button" value="Calculate"                                    /> 
    
    </p>
    
    <!-- (g)  (2 pts)  Fill in the missing HTML close tag 
                       to match the open tag from (e)  -->
    
    
    
    </body>
    </html>
    
  2. Look immediately after part (b) of the previous question, and find the line
    var studTicketsElem = window.document.getElementById(           );
    1. (3 pts) Is getElementById this a property or a method?
    2. (3 pts) What object is getElementById it a property or method of?
    3. (3 pts) Is document a property or a method?
    4. (3 pts) Is studTicketsElem a function, variable, property, or method?
  3. (10 pts) The "stub" function returns -42. This number is significant only in that it is definitely not the correct answer. In just a couple of sentences, explain why it is helpful to write a stub that returns a wrong answer on purpose.







  4. (10 pts) The next step after writing a stub is to write a correct implementation of the function.

    So, complete the function so that it operates correctly. Most of the function is written for you below—you just need to fill in the body part:
    // ticketCalc.js     P. Conrad for CISC103  Midterm Exam 2, 11/08/2007
    
    // define a function that determines the price of a certain
    // number of tickets to the Jon Stewart concert.
    // 
    // Consumes:
    
    
    ... remainder of comment omitted to save space
        see stub function on reference handout for full comment ...
    
    function ticketCalc(numST, numOT)
    {
      // Fill in this part!




    }
  5. (10 pts) At the top of the HTML for web page shown, the following appears:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    This is there so that the page can be "validated", for example by visiting the web site validator.w3.org.

    Briefly explain: what are the benefits of writing HTML that can be validated?







(End of E02, short answer part)