-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
74 lines (50 loc) · 1.53 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const dataUrl = ('http://localhost:3000/pelisc2');
const crearCards = document.getElementById('crearCards');
// cuando se cargue a pagina, va a cargar todo el continido de la api a la pagina HTML
document.addEventListener('DOMContentLoaded', e => {
fetchData();
})
const fetchData = async (filtro = "") => {
try {
const dataUrl1 = await fetch(`${dataUrl}?q=${filtro}`);
const data = await dataUrl1.json()
console.log(data)
// imprimir la data en las cartas
imprimirCards(data);
} catch (error) {
console.log(error)
}
}
const imprimirCards = data => {
let elementos = '';
data.forEach(card => {
elementos += `
<div class="card">
<div class="hero-card">
<figure>
<img src="${card.imagen}" alt="">
</figure>
</div>
<div class="info__card">
<h2 class="card__tittle">${card.nombre}</h2>
<p class="gerero">${card.genero}</p>
<div class="puntuacion__container">
<i class="fa-solid fa-star"></i>
<p>${card.puntaje}</p>
</div>
</div>
</div>
`
});
crearCards.innerHTML = elementos
}
// ------ Filtro ---- //
const search = document.querySelector("form")
search.addEventListener("submit", (event) => {
event.preventDefault()
console.log(event);
let searched = event.target.search.value
console.log(searched)
/* crearCards.innerHTML = "" */
fetchData(searched)
})