-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
27 lines (25 loc) · 906 Bytes
/
script.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
const pokedex = document.querySelector("#grid");
const API = fetch("https://pokeapi.co/api/v2/pokemon?limit=151&offset=0");
API.then((res) => res.json()).then((data) => {
const fetches = data.results.map((pokemon) => {
return fetch(pokemon.url).then((res) => res.json());
});
Promise.all(fetches).then((res) => displayPokemon(res));
});
const displayPokemon = (pokemons) => {
pokemons.forEach((pokemon) => {
const types = [];
pokemon.types.forEach((type) => types.push(type.type.name));
let typesString = types.join(" ");
pokedex.insertAdjacentHTML(
"beforeend",
`<div class="card">
<img src="${pokemon.sprites.other.dream_world.front_default}" alt="${pokemon.name}" class="cardImage"/>
<div class="cardName">
<p class="pokemonName">${pokemon.name}</p>
<p class="types">${typesString}</p>
</div>
</div>`
);
});
};