I'm a complete beginner in javascript and I am using the pokemon api https://pokeapi.co/ to get pokemon images . After I get an image I try to convert it to base64 format but I get the error
pokemon.js:29 Uncaught (in promise) ReferenceError: getBase64 is not defined
I have looked at other answers here about similar issues with this but I am a beginner and cannot understand well .
My code :
var pokeInfo=[];
var pokepics=[];
var pokemon;
//get a pokemon by id
async function fetchPokemon(pokemonID){
var response = await fetch('https://pokeapi.co/api/v2/pokemon/'+pokemonID.toString()+'/');
var poke = await response.json();
pokeInfo.push(poke);
}
//get many pokemon
async function fetchManyPokemon(count){
for(var i=1;i<=count;i++){
await fetchPokemon(count);
}
}
//get pokemon image
async function fetchPokemonImage(pokemonInfo){
var imageUrl = pokemonInfo.sprites.front_default; //select image
var imageResponse = await fetch(imageUrl); //fetch image
var image = await imageResponse.blob(); // get response image
//error is here
var base64 = await getBase64(image); //convert image to base 64 format
pokepics.push(base64);
}
async function fetchPokemonImages(){ //fetch number of pokemon images
for(var l =0;l<pokeInfo.length;l++){
await fetchPokemonImage(pokeInfo[l]);
}
}
I would appreciate your help with guiding me through this issue . Thank you in advance .
getBase64function in this scope, there is also nogetBase64function in the standard JS library. Are you trying to import it from somewhere?