-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
53 lines (43 loc) · 1.55 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { series } from './data.js';
import { Serie } from "./Serie.js";
let table: HTMLElement = document.getElementById("table")!;
let data: HTMLElement = document.getElementById("data")!;
function mostrarListado(data: Serie[], body: HTMLElement): void {
let htmlVar = "";
let sum = 0;
for (let i = 0; i < data.length; i++) {
htmlVar += `
<tr class=\"Serie\">
<td>${data[i].id}</td>
<td id = "nombre-serie">${data[i].name}</td>
<td>${data[i].channel}</td>
<td>${data[i].seasons}</td>
</tr>`
sum += data[i].seasons;
}
htmlVar += `
<tr id = \"average\"><h6>Seasons average: ${sum / data.length}</h2></tr>`;
body.innerHTML = htmlVar;
}
mostrarListado(series, table);
let datav2 : HTMLCollectionOf<Element> = document.getElementsByClassName("Serie");
for (let i = 0; i < data.clientHeight; i++) {
datav2[i].addEventListener("click", () => {
showDetail(i);
});
}
function showDetail(i : number): void {
data.innerHTML = "";
let currentSerie : Serie = series[i];
let card : string = `
<div class="card" style="width: 18rem;">
<img src= "${currentSerie.image}" alt="No se encontró imagen">
<div class="card-body">
<h5 class="card-title">${currentSerie.name}</h5>
<p class="card-text">${currentSerie.description}</p>
<a href="${currentSerie.url}">${currentSerie.url}</a>
</div>
</div>
`;
data.innerHTML = card;
}