Skip to content
Snippets Groups Projects
Commit d8c3de4a authored by Fawx's avatar Fawx
Browse files

upt4

parent 0bfb0e94
No related branches found
No related tags found
No related merge requests found
......@@ -68,9 +68,11 @@ function exc2a() {
console.log(highi)
}
function exc3() {
let ddarr = [];
let ddcolumn = [
1,2,3,4,5,6,7,8,9,10
]
function exc3(cols, rows) {
let ddarr = new Array(cols);
for (var i = 0; i < ddarr.length; i++) {
ddarr[i] = new Array(rows);
}
document.getElementById("exc3").innerHTML = ddarr;
console.log(ddarr)
}
\ No newline at end of file
/**
* Make a table representation of the data
*
* @param {Array[Array[*]]} data The data to represent in the table, a 2D array
* @param {Array[String]} headerRowTexts The strings to show in the header row of the table.
* If null, no header row is created.
*/
function makeTable(data, headerRowTexts = null) {
let table = document.createElement('table');
let thead = document.createElement('thead');
table.append(thead);
// Construct the header row
if (headerRowTexts != null) { // Construct header row
let header = document.createElement('tr');
for(let s of headerRowTexts) {
let thElem = document.createElement('th');
thElem.textContent = s;
header.append(thElem);
}
thead.append(header);
}
// Construct the non-header rows
let tbody = document.createElement('tbody');
for (let row of data) {
let trElem = document.createElement('tr');
for (let value of row) {
let tdElem = document.createElement('td');
tdElem.textContent = value;
trElem.append(tdElem);
}
tbody.append(trElem);
}
table.append(tbody);
return table;
}
/**
* Make a table representation of the array of objects. Note: this function
* can generate an acceptable-looking output table only if the objects of
* objArr are simple enough. For instance, nested objects may lead to table
* cells with too much contents or to cells of the form [object Object] if
* string conversion methods have not been defined for those inner objects.
*
* @param {Array[Object]} objArr
*/
function objectsAsTable(objArr) {
if (objArr.length == 0) {
return makeTable([], null);
}
firstObj = objArr[0];
let header = Object.keys(firstObj);
let arr = objArr.map(e => Object.values(e));
return makeTable(arr, header);
}
\ No newline at end of file
......@@ -13,6 +13,7 @@
</head>
<body>
<script src="coco.js"></script>
<script src="functions.js"></script>
<video autoplay="autoplay" muted="muted" loop="loop" id="myVideo">
<source src="video2.mp4" type="video/mp4">
Your browser does not support HTML5 video.
......@@ -71,13 +72,13 @@
</div>
<div class="w3-container w3-white cori">
<h1 class="">exc3</h1>
<h3></h3>
<h3>check the log for better results</h3>
</div>
<div class="w3-container">
<h5 id="exc3">
<b>3</b>
</h5>
<button onclick="exc3()" class="w3-button btn">exc3</button>
<button onclick="exc3(10,10)" class="w3-button btn">exc3</button>
</div>
<div class="w3-container w3-white cori">
<h1 class="">exc4</h1>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment