Resources
- //INIT: Creating arrays
- //PROCESS: Using arrays
-
//PROCESS:
for
loops - //PROCESS: Using arrays of objects to create a table
- //OUTPUT: Adding elements directly
Saving your work
Use Save as...
to save the
empty
template as
"3.09H-MakeATableWithArraysOfObjects-LastName.html
"
in your Computer Programming directory.
As well, you might want to use some of Drapak's Finger-Savers® in order to help save you some time in typing up repetitive code.
The assignment
Use arrays and for...in
loops to create a table.
You may choose your own level of difficulty.
Solve more problems to get a higher mark
Problem Solving
Remember that a table is composed of the following code:
<table>
<thead>
<tr>
<th>Heading 1</th>
<th>Heading 2</th>
<th>Heading 3</th>
</tr>
</thead>
<tbody id="outputID">
<tr>
<td>item 1a</td>
<td>item 2a</td>
<td>item 3a</td>
</tr>
<tr>
<td>item 1b</td>
<td>item 2b</td>
<td>item 3b</td>
</tr>
</tbody>
</table>
...makes this:
Heading 1 | Heading 2 | Heading 3 |
---|---|---|
item 1a | item 2a | item 3a |
item 1b | item 2b | item 3b |
Make it your own!
If you create your own table of information it does not have to be as large. Create your own, smaller, arrays of information you can display!
Hints
-
Create a
<div>
withid="outputId"
in the body of your code - Create a button that will trigger
mainProcedure()
-
Create an output function that will insert a result into
outputId
- Create a process function to create a table
-
-
Add the
<table>
and<thead>
and<tbody>
first -
Use
for...in
loops to create the rows: -
Add the
<tr>
,<th>
s and the information -
Add the
</tbody>
and</table>
-
Add the
-
Create a
mainProcedure
function that will pass multiple arrays to your process function, and then pass the results to your output function
Evaluation
-
___/10 INIT: include ALL of:
- link to jQuery in the head of your document
- create an array of objects
- add a new object to the array inside the square brackets: []
- separate your array of objects into it's own function that
return
s the completed array
Independent challenge:
- push an object onto the end of your array
-
___/10 HTML-CSS: include ALL of:
-
inside the CSS
- create a different font style or weight for the headings and cells
- create a different background for the headings and cells
- add a border to at least one part of the table table components::
-
create a table with headings
<th>
inside<thead>
-
create a table with data cells
<td>
inside<tbody>
<style>
block: -
___/10 PROCESS: include ALL of:
- create a function that accepts an array of objects as arguments/parameters
- create a separate function to //PROCESS the table code
-
use string addition or
createElement
to create the HTML for the table -
use
for
loops to create a table row for each object in the array
-
___/10 OUTPUT: include ALL FIVE of:
- create a separate function to //OUTPUT the table code
- make that function accept the table code as a parameter/argument
-
use
innerHTML
orappendChild
to display the working table using Javascript
Independent challenges:
- output images in your table using your array of objects
- animate a graph using your array of objects
-
___/10 STYLE: include ALL of:
- honour all previous //STYLE sections
- break up functions into separate ones for input, processing, and output
-
use descriptive comments to identify and describe each function,
and each loop:
//loop through each element of the loop to create the rows