-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
57 lines (51 loc) · 2.2 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
54
55
56
57
import {Serie} from "./Serie.js";
import { dataSeries } from "./data.js";
console.log(dataSeries);
let seriesTable = document.getElementById("id_series")!;
let promedioTable = document.getElementById("avg")!;
let cards= document.getElementById("cards")!;
let botones= document.getElementsByClassName("btn")!;
datosSeries(dataSeries);
promedio(dataSeries);
actualizarCards();
function datosSeries(array: Serie[]):void{
let seriesTbody: HTMLElement = document.createElement("tbody");
for(let sr of array){
let trElement: HTMLElement = document.createElement("tr");
trElement.innerHTML = `<th scope="row">${sr.id}</th>
<td><input type="button" value="${sr.name}" id=${sr.id} class="btn" style="color:blue"></input></td>
<td>${sr.chanel}</td>
<td>${sr.seasons}</td>`;
seriesTbody.appendChild(trElement);
}
seriesTable.appendChild(seriesTbody);
}
function promedio(array: Serie[]):void{
let arrayTemporadas:number[] = []
for(let sr of array){
arrayTemporadas.push(sr.seasons);
}
let suma = arrayTemporadas.reduce((previous, current) => current += previous);
let promedio:number = suma / arrayTemporadas.length;
let trElement:HTMLElement = document.createElement("tr");
trElement.innerHTML = `<td><b>Seasons avarege: </b></td><td>${promedio}</td>`;
promedioTable.appendChild(trElement);
}
function InfoSerie(serie: Serie):void
{
let html = `<img class="card-img-top" src="${serie.image}" alt="Card image cap">
<div class="card-body">
<h5>${serie.name}</h5>
<p class="card-text">${serie.description}\n</p>
<p class="card-text" style="color:blue">${serie.link}</p>
</div>`
cards.innerHTML = html;
}
function actualizarCards():void{
for (var i = 0; i < botones.length; i++)
{
let button: HTMLElement = document.getElementById(botones[i].id)!;
let serie: Serie = dataSeries[Number(botones[i].id)-1];
button.addEventListener("click", (e:Event) => InfoSerie(serie));
}
}