swati-jagtap / javascript-practice

0 stars 0 forks source link

18.1.1--Read the countries API using fetch and print the name of country, capital, languages, population and area #160

Open swati-jagtap opened 3 years ago

swati-jagtap commented 3 years ago

 const countriesAPI = 'https://restcountries.eu/rest/v2/all'
/* const fetchData = async () => {
  try {
    const response = await fetch(countriesAPI)
    const countries = await response.json()
    console.log(countries)
  } catch (err) {
    console.log(err)
  }
}
console.log('===== async and await')
fetchData()
*/

fetch(countriesAPI)
  .then(response=>response.json())
  .then(data=>{
    for(const d of data){
        console.log("Name Of Country :",d["name"])
        console.log("Capital:",d["capital"])
        console.log("Languagds :",d["languages"])
        console.log("Population :",d["population"])
        console.log("Area:",d["area"])
        console.log(" ")
    }
   // console.log(data[1]["name"])
  })

image