I am experiencing my very first run-in with javascript in a college course, and the textbook is not helping me even a little bit. It seems pretty simple, but I just can't get it to work. So here is the problem:
I have to write a function called showTable() to write the following code to the document to create the header row of a table:
<table id='contributors'>
<thead>
<tr>
<th>Date</th><th>Amount</th>
<th>First Name</th><th>Last Name</th>
<th>Address</th>
</tr>
</thead>
I then have to write the 'tbody' tag to the document followed by a for loop to create a row for each person listed in the lastName array. Each time it loops through the array it should add the following code:
<tr>
<td>date</td>
<td class='amt'>amount</td>
<td>firstName</td>
<td>lastName</td>
<td>street <br />
city, state zip
</td>
</tr>
where date, amount, firstName, lastName, street, city, state, and zip are the items from the date, amount, firstName, lastName, street, city, and zip arrays, respectively, corresponding to the value from the counter variable in the for loop.After the for loop, write the '/tbody' tag to close off the table body followed by the closing table tag.
So I wrote what I thought was some code to start off the header row that looks like this:
document.write("<table id='contributors'>")
document.write("<thead>")
document.write("<tr>")
document.write("<th>Date</th><th>Amount</th>")
document.write("<th>First Name</th><th>Last Name</th>")
document.write("<th>Address</th>")
document.write("</tr>")
document.write("</thead>")
If I put this code in the html between script tags it writes the header row to the document, BUT if I put this code in a function in the js file it does nothing. I am really lost and need a kickstart here. If I remember correctly a "function" is supposed to return a value, so I know I must really be missing something here when trying to write this function.
Any help at all would be greatly appreciated! thank you.
John