-
Notifications
You must be signed in to change notification settings - Fork 0
/
pokemons.js
47 lines (39 loc) · 1.38 KB
/
pokemons.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
window.onload = function() {
if(!window.location.hash) {
window.location = window.location + '#carregar';
window.location.reload();
}
}
if(Object.keys(sessionStorage).length === 1){
console.log('este é o', sessionStorage);
}
if(Object.keys(sessionStorage).length < 2){ //Test if the sessionStorage isn't empty
// window.location.reloa;d()
let url = 'https://pokeapi.co/api/v2/pokemon?limit=28';
function fetchPokemon() {
fetch(url).then(
(response) => response.json()
).then(function(data){
data.results.forEach((pokemon, index) => {
getEachPoke(pokemon.url);//Call the function that pick any pokemon individually
});
}).catch((error) => console.log(error));
}
setTimeout(() => {
fetchPokemon();
}, 1000)
function getEachPoke(url){
fetch(url).then(
(response) => response.json()
).then(function(data){
storeDataPokemon(data);
}).catch((error) => console.log(error));
}
async function storeDataPokemon(data) {
let imgPokemon = data['sprites']['other']['official-artwork']['front_default'];
let namePokemon = data['name'];
sessionStorage.setItem(`${namePokemon}`, `${imgPokemon}`);
}
}else{
console.log('entrou no else');
}