-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo.js
33 lines (28 loc) · 1.28 KB
/
info.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
const pokemonName = window.location.search.split('=')[1];
const API_URL = `https://pokeapi.co/api/v2/pokemon/${pokemonName}`;
const infoWrapper = document.getElementById('info-wrapper');
async function fetchPokemonInfoByName() {
const response = await fetch(API_URL);
const pokemon = await response.json();
// const pokemonImage = pokemon.sprites.other.dream_world.front_default;
// const pokemonAbilities = pokemon.abilities;
// const pokemonStats = pokemon.stats;
// const pokemonTypes = pokemon.types;
// const pokemonHeight = pokemon.height;
// const pokemonWeight = pokemon.weight;
generateInfo(pokemon);
console.log(pokemon);
}
function generateInfo(obj) {
const nameContainer = document.createElement('div');
nameContainer.classList.add('info-text');
nameContainer.innerText = pokemonName;
const imageContainer = document.createElement('div');
imageContainer.classList.add('info-image');
const pokemonImage = document.createElement('img');
pokemonImage.setAttribute('src', obj.sprites.other.dream_world.front_default);
imageContainer.appendChild(pokemonImage);
infoWrapper.appendChild(nameContainer);
infoWrapper.appendChild(imageContainer);
}
document.addEventListener('DOMContentLoaded', fetchPokemonInfoByName());