CSCI 121 - Lab 4
Lab Resources
Lab Instructions
In this lab you will be authoring a web page that showcases how to use JavaScript functions, the switch statement, for loops and the Document Object Model (the last in a rudimentary fashion). The goal is to provide a page that displays an "old-fashioned" Multiplication Table. Please read through all of the instructions below before starting.
- Start: Use Brackets to create a file named lab4.html.
- Include a title for the page with your name, class and lab, i.e. Your Name - CSCI 121, Lab 4
- Repeat the title text as the heading for the page.
- Your document should have main background and text colors OTHER THAN white text on a black background by changing the style of one element
only in the document. Change in the STYLE block of the HEAD.
- Your document must included a captioned table with 12 rows, 12 columns, each cell having a width and height of 40 pixels as shown below.
- Use a STYLE block in the HEAD section to style the table, its rows, its cells. To stylize the table elements DO NOT specify style or set formatting attributes on individual TR, TD elements within the BODY.
- Have three "buttons" on your page below the table, labeled as shown below.
- Checkpoint 1: The page should initially look like this (not to scale):
- Continue: Next, you will add the code that will fill the top header row and the first column of each subsequent row with text labels when the "Fill headers" button is clicked.
- To fill the header row (1st row starting with 2nd column) and label column (1st column of each row starting with second row) you should:
- Add ID attributes to each of the TD elements needed to be filled with a label. See "Hints" section below.
- Code a function entitled: fillHeaders()
- The fillHeaders() function should have a single for loop that internally places a label (Zero, One, Two...) within the innerHTML of each of the TD elements that make up the header row and first column of each row.
- The for loop should utilize another function called getLabel() which is passed in a single parameter named num, which is a number variable, having a value between 0 and 10, inclusive.
- The getLabel() function must return a string corresponding to the label of the number passed in (e.g. 0 returns "Zero", 1 returns "One",...).
- The getLabel() function must use a switch statement internally to perform its main task of returning the appropriate text label given a supplied number.
- Make sure to wire up the "Fill headers" button so that it calls the fillHeaders() function by populating its onclick event.
- Checkpoint 2: The page should look like this when clicking the "Fill headers" button:
- Continue: Next, you will add the code that will fill the rest of the table when the user clicks the "Fill table" button.
- To fill the table you should:
- Add ID attributes to each of the TD elements needed to be filled with a product (row x col). See "Hints" section below.
- Code a function entitled: fillTable()
- The fillTable() function should have two for loops, one nested within the other used for setting the innerHTML of each appropriate TD element to the product of the row and column values of the Multiplication Table.
- Make sure to wire up the "Fill table" button so that it calls the fillTable() function by populating its onclick event.
- Checkpoint 3: The page should look like this when clicking the "Fill tables" button:
- Extra Credit: Add a "Reload" button like the one shown and add the JavaScript code behind it that will cause the page to reload, essentially clearing the table.
- At the bottom of the page include a mailto link with the following syntax (change your_email accordingly):
- <a href="mailto:your_email@millersville.edu?subject=Lab 4 Grade">Email grade</a>
- Important notes/hints:
- Make sure to name the file: lab4.html
- For the sake of easier grading please limit your lab to the single lab4.html file only.
- Make sure that your mailto: link uses your Millersville email address and does not include spaces anywhere.
- The reason for adding ID attributes to the TDs is so that those elements may be refereced within functions through the use of: document.getElementById();
- ID values that are derived from a row, column, product convention that takes into account column number, row number, and product cell will likely be very useful (required) in your for loops when referencing TD elements. Examples of ID formats that might help are: "c0", ... "c10", "r0", ... "r10", "p0x0", "p0x1", ... "p10x10".
- Use the debugger in Chrome when testing.
- Test "as you go", at each checkpoint.
- Upload the lab4.html file to Google Docs, storing in your "CSCI 121" folder.
- Share the lab4.html file with thomas.rogers@millersville.edu.
Lab 4 Sample
Lab 4 sample page here.
Lab 4 Observations
Lab 4 observations here.