-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
68 lines (51 loc) · 1.56 KB
/
index.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
const info = document.getElementById("info")
const anterior = document.getElementById("anterior")
const siguiente = document.getElementById("sig")
var next = ""
var previous = ""
var url = "https://pokeapi.co/api/v2/pokemon"
siguiente.addEventListener('click', ()=>{
info.innerHTML = ""
obtenerPokemones(next)
})
anterior.addEventListener('click', () =>{
info.innerHTML = ""
obtenerPokemones(previous)
})
const obtenerPokemones = async (url) => {
var data = []
var habilidades = ""
data = await fetch(url)
var json = await data.json()
next = json.next
previous = json.previous
console.log(previous)
if(previous == undefined){
anterior.hidden = true
}else{
anterior.hidden = false
}
for (var pokemon of json.results) {
var res = await fetch(pokemon.url)
var jsonInfo = await res.json()
for(var hab of jsonInfo.abilities){
habilidades += `<p class="card-text" >${hab.ability.name}</p>`
}
info.innerHTML += `<div class="card mb-3 ">
<div class="row g-0">
<div class="col-md-4">
<img src=${jsonInfo.sprites.front_shiny} class="rounded mx-auto d-block" alt=${pokemon.name}">
</div>
<div class="col-md-8">
<div class="card-body">
<h3 class="card-title">${pokemon.name}</h3>
<h5>Habilidades :</h5>
<p >${habilidades}</p>
</div>
</div>
</div>
</div>`
habilidades = ""
}
}
obtenerPokemones(url)