Resources
- //INIT: Creating arrays
- //PROCESS: Using arrays
-
//PROCESS:
for
loops - //OUTPUT: Adding elements directly
Saving your work
Use Save as...
to save the
empty template as
"3.09H-MakeATable-LastName.html
"
in your Computer Programming 12 directory.
The assignment
Use arrays and for...in
loops to create a table.
You may choose your own level of difficulty.
You do not have to use the top 20 sites data -
but if you choose your own data, make sure that your table is not too large
For example
The top 20 websites in Canada!
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 -
Reread //PROCESS:
for
loops for more info
Evaluation
-
___/10 INIT: including
- add to an array inside the square brackets
-
add to an array using bracket notation:
(
exampleArr [ 7 ]
) - add to an array using .length
- add to an array using .push()
-
___/10 HTML-CSS:
inside the CSS
<style>
block, include:-
create a table with headings
<th>
inside<thead>
-
create a table with data cells
<td>
inside<tbody>
- 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
-
create a table with headings
-
___/10 PROCESS: including
- create a function that accepts an array/arrays as arguments/parameters
- use string addition or createElement() to create HTML code
- use
for
loops to create table rows - join together information from more than one array at a time
- return information from a function
-
___/10 STYLE: including
- honour all previous //STYLE sections
- use descriptive variable names
- 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
-
add spaces between mathematical and string operators,
for example:var exampleVar = "hello " + "kitty"
, notvar exampleVar="hello "+"kitty"
.