-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
30 lines (22 loc) · 939 Bytes
/
main.ts
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
import { Serie } from './serie.js';
import { data } from './data.js';
let seriesTbody: HTMLElement = document.getElementById('series')!;
const averageSeasonsElm: HTMLElement = document.getElementById("averageSeasons")!;
renderSeriesInTable(data);
averageSeasonsElm.innerHTML = `${getAverageSeasons(data)}`
function renderSeriesInTable(series: Serie[]): void {
console.log('Desplegando series');
series.forEach((serie) => {
let trElement = document.createElement("tr");
trElement.innerHTML = `<td>${serie.id}</td>
<td>${serie.name}</td>
<td>${serie.channel}</td>
<td>${serie.seasons}</td>`;
seriesTbody.appendChild(trElement);
});
}
function getAverageSeasons(series: Serie[]): number {
let totalSeasons: number = 0;
series.forEach((serie) => totalSeasons = totalSeasons + serie.seasons);
return totalSeasons/series.length;
}