Retrieve data from an API with JavaScript️

Retrieve data from an API with JavaScript️

HomeBro CodeRetrieve data from an API with JavaScript️
Retrieve data from an API with JavaScript️
ChannelPublish DateThumbnail & View CountDownload Video
Channel AvatarPublish Date not found Thumbnail
0 Views
#javascript #tutorial #course

00:00:00 pick up
00:06:29 async/wait
00:08:55 project

// fetch Function used to make HTTP requests to fetch resources.
// (JSON style data, images, files)
// Simplifies asynchronous data retrieval in JavaScript and
// used to interact with APIs to retrieve and send
// data asynchronously over the internet.
// get(url, {options})

asynchronous function fetchData(){

attempt{

const pokemonName document.getElementById(/"pokemonName/").value.toLowerCase();
const response waiting to be retrieved (https://pokeapi.co/api/v2/pokemon/{pokemonName});

if(!response.ok){
throw new Error(/"Could not get source/");
}

const data waiting for response.json();
const pokemonSprite data.sprites.front_default;
const imgElement document.getElementById(/"pokemonSprite/");

imgElement.src pokemonSprite;
imgElement.style.display /"block/";
}
catch(error){
console.error(error);
}
}

Please take the opportunity to connect and share this video with your friends and family if you find it useful.