-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpokedex.js
More file actions
180 lines (161 loc) · 5.49 KB
/
pokedex.js
File metadata and controls
180 lines (161 loc) · 5.49 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
const pokeNameInput = document.getElementById("pokeName");
const PokeId = document.getElementById('pokeNumber');
const pokeAltura = document.getElementById('altura');
const pokePeso = document.getElementById('peso');
const pokeTipo = document.getElementById('tipos');
const pokeTipo1 = document.getElementById('type1-screen');
const pokeTipo2 = document.getElementById('type2-screen');
const pokeVida = document.getElementById('hp');
const pokeAtaque = document.getElementById('ataque');
const pokeDefensa = document.getElementById('defensa');
const pokeAtEsp = document.getElementById('ataque-esp');
const pokeDefEsp = document.getElementById('defensa-esp');
const pokeVelocidad = document.getElementById('velocidad');
const fetchPokemon = () => {
let pokeName = pokeNameInput.value;
pokeName = pokeName.toLowerCase();
const url = `https://pokeapi.co/api/v2/pokemon/${pokeName}`;
fetch(url).then((res) => {
if (res.status != "200") {
console.log(res);
pokeImage("./img/pikachu-sad.jpg")
alert("El nombre ingresado no coincide con ningún Pokémon, vuelve a intentarlo :)");
}
else {
return res.json();
}
}).then((data) => {
if (data) {
console.log(data);
limpiar();
let pokeImg = data.sprites.front_default;
let pokeImgShiny = data.sprites.front_shiny;
pokeImage(pokeImg);
pokeImageShiny(pokeImgShiny)
let pokeNum = data.id;
let pokeNombre = data.name.toUpperCase();
PokeId.innerHTML = `N°${pokeNum} ${pokeNombre}`;
pokeAltura.innerHTML = `Altura: ${data.height / 10}m`;
pokePeso.innerHTML = `Peso: ${data.weight / 10}kg`;
if (data.types.length == 1){
let type = data.types[0].type.name;
let tipo = traducirTipo(type);
pokeTipo.innerHTML = `Tipo: ${tipo}`;
pokeTipo1.innerHTML = `${tipo}`;
}
else{
let type1 = data.types[0].type.name;
let type2 = data.types[1].type.name;
let tipo1 = traducirTipo(type1);
let tipo2 = traducirTipo(type2);
pokeTipo.innerHTML = `Tipos: ${tipo1}/${tipo2}`;
pokeTipo1.innerHTML = `${tipo1}`;
pokeTipo2.innerHTML = `${tipo2}`;
}
pokeVida.innerHTML = `HP: ${data.stats[0].base_stat} - VEL: ${data.stats[5].base_stat}`;
pokeAtaque.innerHTML = `ATAK: ${data.stats[1].base_stat} - DEF: ${data.stats[2].base_stat}`;
pokeAtEsp.innerHTML = `AT.ESPECIAL: ${data.stats[3].base_stat}`;
pokeDefEsp.innerHTML = `DEF.ESPECIAL: ${data.stats[4].base_stat}`;
}
});
}
const traducirTipo = (type) => {
if (type == 'bug'){
type = 'BICHO';
}
else if (type == 'dark'){
type = 'SINIESTRO';
}
else if (type == 'dragon'){
type = 'DRAGON';
}
else if (type == 'electric'){
type = 'ELECTRICO';
}
else if (type == 'fairy'){
type = 'HADA';
}
else if (type == 'fighting'){
type = 'LUCHA';
}
else if (type == 'fire'){
type = 'FUEGO';
}
else if (type == 'flying'){
type = 'VOLADOR';
}
else if (type == 'ghost'){
type = 'FANTASMA';
}
else if (type == 'grass'){
type = 'PLANTA';
}
else if (type == 'ground'){
type = 'TIERRA';
}
else if (type == 'ice'){
type = 'HIELO';
}
else if (type == 'normal'){
type = 'NORMAL';
}
else if (type == 'poison'){
type = 'VENENO';
}
else if (type == 'psychic'){
type = 'PSIQUICO';
}
else if (type == 'rock'){
type = 'ROCA';
}
else if (type == 'steel'){
type = 'ACERO';
}
else if (type == 'water'){
type = 'AGUA';
}
return type;
}
const pokeImage = (url) => {
const pokePhoto = document.getElementById("pokeImg");
pokePhoto.src = url;
}
const pokeImageShiny = (url) => {
const pokePhoto2 = document.getElementById("pokeImgColor");
pokePhoto2.src = url;
}
const verStats = (obj) =>{
document.getElementById('stats-screen').style.visibility = 'visible';
obj.style.backgroundColor = "#fecb65";
document.getElementById('info').style.backgroundColor = '#ffffff';
}
const verInfo = (obj) =>{
document.getElementById('stats-screen').style.visibility = 'hidden';
obj.style.backgroundColor = "#fecb65";
document.getElementById('stats').style.backgroundColor = '#ffffff';
}
const verShiny = () => {
document.getElementById('shiny-sprite').style.backgroundColor = '#ff0000';
document.getElementById('normal-sprite').style.backgroundColor = '#85bdfe';
document.getElementById('screen-shiny').style.visibility = 'visible';
}
const verNormal = () => {
document.getElementById('shiny-sprite').style.backgroundColor = '#85bdfe';
document.getElementById('normal-sprite').style.backgroundColor = '#ff0000';
document.getElementById('screen-shiny').style.visibility = 'hidden';
}
const limpiar = () => {
pokeNameInput.innerHTML = '';
PokeId.innerHTML = '';
pokeAltura.innerHTML = '';
pokePeso.innerHTML = '';
pokeTipo.innerHTML = '';
pokeTipo1.innerHTML = '';
pokeTipo2.innerHTML = '';
pokeVida.innerHTML = '';
pokeAtaque.innerHTML = '';
pokeDefensa.innerHTML = '';
pokeAtEsp.innerHTML = '';
pokeDefEsp.innerHTML = '';
pokeVelocidad.innerHTML = '';
}