-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
70 lines (58 loc) · 1.95 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
69
70
const fetchPokemon = async() => {
const pokeNameInput = document.getElementById("pokeName");
let pokeName = pokeNameInput.value;
pokeName = pokeName.toLowerCase();
const url = `https://pokeapi.co/api/v2/pokemon/${pokeName}`;
let data = await fetch(url).then((res) => {
if (res.status != "200") {
console.log(res);
pokeImage("./pokemon-sad.gif")
} else {
return res.json();
}
});
if (data) {
console.log(data);
let pokeImg = data.sprites.front_default;
let pokeInfo1 = data.abilities;
let pokeInfo2 = data.stats;
pokeImage(pokeImg);
pokeData(pokeInfo1);
pokeData2(pokeInfo2);
pokeData3(pokeInfo2);
pokeData4(pokeInfo2);
pokeData5(pokeInfo2);
console.log(pokeImg);
}
};
const pokeImage = (url) => {
const pokePhoto = document.getElementById("pokeImg");
pokePhoto.style.width = "150px"
pokePhoto.src = url;
pokePhoto.style.margin = "0px 50px 0px 50px"
}
const pokeData = (abilities) => {
const pokeAbilities = document.getElementById("abilities");
const abilitiesName = abilities.map(item => item.ability.name);
pokeAbilities.innerHTML = "<p>Habilidades:</p>" + abilitiesName.join(','+'\n')
}
const pokeData2 = (stats) =>{
const pokeHp = document.getElementById("hp");
const hp = stats[0].base_stat;
pokeHp.innerHTML = "<p>Hp: <p>" + hp
}
const pokeData3 = (stats) => {
const pokeDef = document.getElementById("defensa");
const def = stats[2].base_stat;
pokeDef.innerHTML = "<p>Defensa: <p>" + def
}
const pokeData4 = (stats) => {
const pokeAtt = document.getElementById("ataque");
const att = stats[1].base_stat;
pokeAtt.innerHTML = "<p>Ataque:<p>" + att
}
const pokeData5 = (stats => {
const pokeSpeed = document.getElementById("velocidad");
const speed = stats[5].base_stat;
pokeSpeed.innerHTML = "<p>Velocidad: <p>" + speed
})