-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.js
71 lines (61 loc) · 2.55 KB
/
api.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
const listaPokemon = document.querySelector("#lista-pokemon");
// Math.random()
// Esta funcion devuelve un número aleatorio situado entre dos valores específicos. El valor devuelto será mayor o igual que min y menor que max.
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
document.addEventListener("DOMContentLoaded", () => {
let i = 0
while (i <= 10) {
const ramdom = getRandomInt(1, 152)
obtenerPokemons(ramdom)
i = i + 1
}
})
// Recorre el objeto con todos los Pokemon
function obtenerPokemons(id) {
const URLPOKEMONS = `https://pokeapi.co/api/v2/pokemon/${id}`;
// Petision de todos los pokemons
fetch(URLPOKEMONS)
.then(response => response.json())
.then(dataPoke => {
cardPokemon(dataPoke)
})
.catch((error => console.log(error)));
}
// impresion grafica de los pokemons
function cardPokemon(dataPokemons) {
listaPokemon.innerHTML += `
<div class="card" style="width: 25rem;">
<img src="${dataPokemons.sprites.other.dream_world.front_default}" alt="imagen de vitoko" class="card-body-img">
<div class="card-body">
<a class="card-title">${dataPokemons.name}</a>
<p class="card-text">${dataPokemons.base_experience}</p>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item">
<h3>${dataPokemons.stats[1].base_stat}k</h3>
<p>${dataPokemons.stats[1].stat.name}</p>
<a href="#" class="card-link list-group-item">
<h3>${dataPokemons.stats[3].stat.name} ${dataPokemons.stats[3].base_stat}K</h3>
</a>
</li>
<li class="list-group-item">
<h3>${dataPokemons.stats[2].base_stat}k</h3>
<p>${dataPokemons.stats[2].stat.name}</p>
<a href="#" class="card-link list-group-item">
<h3>${dataPokemons.stats[4].stat.name} ${dataPokemons.stats[5].base_stat}K</h3>
</a>
</li>
</ul>
<div class="card-body flex-row">
<p href="#" class="card-link list-group-item">
${dataPokemons.abilities[1].ability.name}
</p>
<p href="#" class="card-link list-group-item">
${dataPokemons.abilities[2].ability.name}
</p>
</div>
</div>
`;
}