-
Notifications
You must be signed in to change notification settings - Fork 0
/
pokemon.js
39 lines (33 loc) · 1.07 KB
/
pokemon.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
const MAX_POKEMON = 151;
const listWrapper = document.querySelector(".list-wrapper");
const searchInput = document.querySelector("#search-input");
const numberFilter = document.querySelector("#number");
const nameFilter = document.querySelector("#name");
const notFoundMessage = document.querySelector("#not-found-message");
let allPokemons = [];
fetch(`https://pokeapi.co/api/v2/pokemon?limit=${MAX_POKEMON}`)
.then((response) => response.json())
.then((data) => {
allPokemons = data.results;
});
async function fetchPokemonBeforeRedirect(id) {
try {
const [pokemon, pokemonSpecies] = await Promise.all([
fetch(`https://pokeapi.co/api/v2/pokemon/${id}`).then((res) =>
res.json()
),
fetch(`https://pokeapi.co/api/v2/pokemon-species/${id}`).then((res) =>
res.json()
),
]);
return true;
} catch {
console.error("Unable to fetch pokemon data before redirect");
}
}
function displayPokemons(pokemon){
listWrapper.innerHTML = "";
pokemon.forEach((pokemon) => {
const pokemonID = pokemon.url.split("/")[6]
});
}