Skip to main content

Command Palette

Search for a command to run...

[JavaScript] Asynchronous JavaScript: Promises, Async/Await, and AJAX - Consuming Promises

Published
View as Markdown
// const request = fetch(`https://restcountries.com/v2/name/portugal`);
// console.log(request);

// const getCountryData = function (country) {
//   fetch(`https://restcountries.com/v2/name/${country}`)
//     .then(function (response) {
//       console.log(response);
//       return response.json();
//     })
//     .then(function (data) {
//       console.log(data);
//       renderCountry(data[0]);
//     });
// };

const getCountryData = function (country) {
  fetch(`https://restcountries.com/v2/name/${country}`)
    .then(response => response.json())
    .then(data => renderCountry(data[0]));
};

getCountryData('Spain');
getCountryData('usa');

consuming.PNG

JavaScript

Part 1 of 50

More from this blog

Jayden's Blog

166 posts