forked from alazzuri/ejercicio-pokemons
-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils_NO_TOCAR.js
66 lines (61 loc) · 1.77 KB
/
utils_NO_TOCAR.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
// NO TOCAR
const statsNames = {
hp: "hp",
attack: "ataque",
defense: "defesa",
speed: "velocidade",
};
// NO TOCAR
function createPokemonCard(pokemon, order) {
const body = document.querySelector("main");
const cardContainer = document.createElement("div");
cardContainer.className = "card";
cardContainer.innerHTML = `
<img
src="..."
class="card-img-top"
alt="pokemon-${order}"
id="pokemon-image-${order}"
/>
<div class="card-body">
<h5 class="card-title" id="pokemon-name-${order}">${pokemon.toUpperCase()}</h5>
<p class="card-text">Skills</p>
<span>HP</>
<div class="bar-container">
<div id="hp-bar-${order}"></div>
<span id="hp-amount-${order}"></span>
</div>
<span>Ataque</>
<div class="bar-container">
<div id="attack-bar-${order}"></div>
<span id="attack-amount-${order}"></span>
</div>
<span>Defesa</>
<div class="bar-container">
<div id="defense-bar-${order}"></div>
<span id="defence-amount-${order}"></span>
</div>
<span>Velocidade</>
<div class="bar-container">
<div id="speed-bar-${order}"></div>
<span id="speed-amount-${order}"></span>
</div>
</div>
`;
body.appendChild(cardContainer);
}
// NO TOCAR
async function getPokemonData(name) {
const response = await fetch(`https://pokeapi.co/api/v2/pokemon/${name}`);
const json = await response.json();
const parsedData = {
stats: json.stats
.map((stat) => ({
name: statsNames[stat.stat.name],
amount: stat["base_stat"],
}))
.filter((stat) => stat.name),
imagen: json.sprites["front_default"],
};
return parsedData;
}