Hello everyone!
<div id="sprite"></div>
const spriteBox = document.getElementById("sprite")
const fetchPokemon = async () => {
try {
const pokemonNameOrId = input.value.toLowerCase()
const res = await fetch(`https://pokeapi-proxy.freecodecamp.rocks/api/pokemon/${pokemonNameOrId}`);
const data = await res.json();
printPokemonData(data);
} catch (err) {
alert("Pokémon not found")
}
};
const printPokemonData = data => {
const { name, id, weight, height, types, sprites, stats } = data;
spriteBox.innerHTML = `<img src="${sprites.front_default}" id="sprite">`
}
search.addEventListener("click", elem => {
elem.preventDefault()
fetchPokemon()
});
........
I’m having a problem passing the two image tests while the pictures do appear in the preview and the code seems to be correct? Any ideas? Thanks in advance. I’ve cut out the irrelevant code to make it easier to read.
[Error: TypeError: sprite.src is undefined]
[Error: TypeError: sprite.src is undefined]