-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
60 lines (59 loc) · 2.13 KB
/
main.js
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
58
59
60
"use strict";
import { series as _series } from "./data.js";
console.log(_series);
var table = document.getElementById("table-container");
if (table) {
var tbody_1 = document.createElement("tbody");
_series.forEach(function (serie) {
var tr = document.createElement("tr");
var idCell = document.createElement("td");
idCell.textContent = serie.id.toString();
var link = document.createElement("a");
link.href = "#" + serie.id.toString();
link.textContent = serie.title;
link.addEventListener("click", function (event) {
event.preventDefault(); // Prevents the default link behavior
var image = document.getElementById("image");
;
var title = document.getElementById("title");
var description = document.getElementById("description");
var link = document.getElementById("link");
if (image)
image.src = serie.imageUrl;
if (title)
title.textContent = serie.title;
if (description)
description.textContent = serie.synopsis;
if (link)
link.textContent = serie.url;
});
var titleCell = document.createElement("td");
titleCell.appendChild(link);
var channelCell = document.createElement("td");
channelCell.textContent = serie.channel;
var seasonsCell = document.createElement("td");
seasonsCell.textContent = serie.seasons.toString();
tr.appendChild(idCell);
tr.appendChild(titleCell);
tr.appendChild(channelCell);
tr.appendChild(seasonsCell);
tbody_1.appendChild(tr);
});
table.appendChild(tbody_1);
var average = document.getElementById("average");
if (average) {
if (average.textContent) {
average.innerText = getAverage(_series).toString();
}
}
}
function getAverage(series) {
var suma = 0;
var counter = 0;
series.forEach(function (serie) {
suma = suma + serie.seasons;
counter = counter + 1;
});
var promedio = suma / counter;
return promedio;
}