-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
25 lines (20 loc) · 1002 Bytes
/
app.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
const getPokemonUrl = id => `https://pokeapi.co/api/v2/pokemon/${id}`
const generatePokemonPromises = () => Array(150).fill().map((_, index) => fetch(getPokemonUrl(index + 1)).then(response => response.json()))
const generateHTML = pokemon => pokemon.reduce((accumulator, { name , id, types}) => {
const elemType = types.map(typeInfo => typeInfo.type.name)
accumulator += `
<li class="card ${elemType[0]}">
<img class="card-image" alt="$${name}" src="https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/${id}.png"></img>
<h2 class="card-title">${id}. ${name}</h2>
<p class="card-subtitle">${elemType.join(" | ")}</p>
</li>`
return accumulator
}, "")
const insertPokemon = pokemon => {
const ul = document.querySelector('[data-js="pokedex"]')
ul.innerHTML = pokemon
}
const pokemonPromises = generatePokemonPromises()
Promise.all(pokemonPromises)
.then(generateHTML)
.then(insertPokemon)