forked from CUNYTechPrep/eloquentjs-problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchapter13.js
More file actions
39 lines (32 loc) · 1.1 KB
/
Copy pathchapter13.js
File metadata and controls
39 lines (32 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
* Add your solution to the chapter 13 problem from the eloquentjs book.
* - DO NOT rename the functions below.
* - You may add other functions if you need them.
* - You may rename the parameters.
* - DO NOT modify the number of parameters for each function.
*/
// Problem 1: Build table
function buildTable(data) {
// Your code here
var table = document.createElement("table");
var row = document.createElement("tr");
var cells = Object.keys(data[0]);
for(var i in cells) {
var header = document.createElement("th");
header.appendChild(document.createTextNode(cells[i]));
row.appendChild(header);
}
table.appendChild(row);
for(var data1 in data) {
var rowInfo = document.createElement("tr");
for(var data2 in cells) {
var rowData = document.createElement("td");
rowData.appendChild(document.createTextNode(data[data1][cells[data2]]));
rowInfo.appendChild(rowData);
}
table.appendChild(rowInfo);
}
return table;
}
// Do not modify below here.
module.exports = { buildTable };