hey guys for some odd reason when i press enter all the data gets displayed but not the sprite image and the types i dont know wherer i went wrong can somebody help me please? code is below
const searchInput = document.getElementById("search-input");
const searchButton = document.getElementById("search-button");
const pokemonName = document.getElementById("pokemon-name");
const pokemonId = document.getElementById("pokemon-id");
const pokemonWeight = document.getElementById("weight");
const pokemonHeight = document.getElementById("height");
const pokemonTypes = document.getElementById("types");
const hp = document.getElementById("hp");
const attack = document.getElementById("attack");
const defense = document.getElementById("defense");
const pokemonSpAtt = document.getElementById("special-attack");
const pokemonSpDef = document.getElementById("special-defense");
const pokemonSpeed = document.getElementById("speed");
const sprites = document.getElementById("sprite-container");
const getPokemon = async () => {
try {
const pokemonNameorid = searchInput.value.toLowerCase();
const res = await fetch(`https://pokeapi-proxy.freecodecamp.rocks/api/pokemon/${pokemonNameorid}`);
const data = await res.json();
getPokemonInfo(data);
} catch (err) {
alert("Pokémon not found");
console.log(err);
}
};
const getPokemonInfo = data => {
const {name , id , weight, height, types , sprites , stats} = data;
pokemonName.textContent = `${name[0].toUpperCase() + name.slice(1)}`
pokemonId.textContent = `#${id}`
pokemonWeight.textContent = ` weight: ${weight}`
pokemonHeight.textContent = ` height ${height}`
sprites.innerHTML = `<img src='${sprites.front_default}' alt='${name}' />`
hp.textContent = stats[0].base_stat;
attack.textContent = stats[1].base_stat;
defense.textContent = stats[2].base_stat;
pokemonSpAtt.textContent = stats[3].base_stat;
pokemonSpDef.textContent = stats[4].base_stat;
pokemonSpeed.textContent = stats[5].base_stat;
pokemonTypes.innerHTML = types.map(obj => {
`<span>${obj.type.name[0].toUpperCase() + obj.type.name.slice(1)}</span>`;
})
};
searchButton.addEventListener("click", e => {
e.preventDefault;
getPokemon();
});