forked from Launch-X-Latam/MisionFrontEnd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4.-pokedex.js
More file actions
30 lines (26 loc) · 774 Bytes
/
4.-pokedex.js
File metadata and controls
30 lines (26 loc) · 774 Bytes
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
const fetchPokemon = () => {
const pokeNameInput = document.getElementById("pokeName");
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("./pokemon-sad.gif")
}
else {
return res.json();
}
}).then((data) => {
if (data) {
console.log(data);
let pokeImg = data.sprites.front_default;
pokeImage(pokeImg);
console.log(pokeImg);
}
});
}
const pokeImage = (url) => {
const pokePhoto = document.getElementById("pokeImg");
pokePhoto.src = url;
}