-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (37 loc) · 1.49 KB
/
index.js
File metadata and controls
44 lines (37 loc) · 1.49 KB
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
fetchPokemon()
function fetchPokemon(){
fetch('https://pokeapi.co/api/v2/pokemon/?limit=150')
.then(response => response.json())
.then(function(allpokemon){
allpokemon.results.forEach(function(pokemon){
fetchPokemonData(pokemon)
})
})
}
function fetchPokemonData(pokemon){
let url = pokemon.url
fetch(url)
.then(response => response.json())
.then(function(pokeData){
renderPokemon(pokeData)
})
}
function renderPokemon(pokeData){
let allPokemonContainer = document.getElementById('pokedex')
let pokeContainer = document.createElement("div")
pokeContainer.setAttribute("class","pokeCont")
let pokeInfo = document.createElement("div")
let pokeName = document.createElement('h4')
pokeName.textContent = pokeData.name
let pokeImage = document.createElement('img')
pokeImage.srcset = `https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/${pokeData.id}.png`
pokeImage.setAttribute("class","pokeIm")
console.log(pokeContainer)
let pokeNumber = document.createElement('p')
pokeNumber.textContent = `#${pokeData.id}`
pokeInfo.append(pokeName, pokeNumber)
pokeContainer.append(pokeImage, pokeInfo)
allPokemonContainer.appendChild(pokeContainer)
}
function renderInformation(){
}