jonasschmedtmann / complete-javascript-course

Starter files, final projects, and FAQ for my Complete JavaScript course
https://www.udemy.com/the-complete-javascript-course/?couponCode=C3GITHUB10
15.74k stars 16.84k forks source link

Country API Issues while rendering (Complete Solution) #436

Open saroshkhann opened 2 months ago

saroshkhann commented 2 months ago

////// Instead of writing this code

<article class="country">
         <img class="country__img" src="${data.flags.png}" />
         <div class="country__data">
           <h3 class="country__name">${data.name.common}</h3>
           <h4 class="country__region">${data.region}</h4>
           <p class="country__row"><span>πŸ‘«</span>${(
             +data.population / 1000000
          ).toFixed(1)} people</p>
           <p class="country__row"><span>πŸ—£οΈ</span>${data.languages.urd}</p>
          <p class="country__row"><span>πŸ’°</span>${data.currencies.name}</p>
         </div>
       </article>

///// Write this code

<article class="country ${className}">
          <img class="country__img" src="${data.flags.png}" />
          <div class="country__data">
            <h3 class="country__name">${data.name.common}</h3>
            <h4 class="country__region">${data.region}</h4>
            <p class="country__row"><span>πŸ‘«</span>${(
              +data.population / 1000_000
            ).toFixed(1)}</p>
            <p class="country__row"><span>πŸ—£οΈ</span>${Object.values(
              data.languages
            ).join()}</p>
            <p class="country__row"><span>πŸ’°</span>${Object.keys(
              data.currencies
            ).join()}</p>
          </div>
</article>

//////////// Also destructure data2 in request2 event handler

const [data2] = JSON.parse(this.responseText);

InnocentCode4ui commented 2 months ago

on chaining promises the neighbour country does not want to appear saying TypeError: Cannot read properties of undefined reading png... i dont know why is that.help please... Screenshot (77)

saroshkhann commented 2 months ago

on chaining promises the neighbour country does not want to appear saying TypeError: Cannot read properties of undefined reading png... i dont know why is that.help please... Screenshot (77)

At line 79 change the code like this: .then(data=> renderCountry(data[0], "neighbour"));

InnocentCode4ui commented 2 months ago

on chaining promises the neighbour country does not want to appear saying TypeError: Cannot read properties of undefined reading png... i dont know why is that.help please... Screenshot (77)

At line 79 change the code like this: .then(data=> renderCountry(data[0], "neighbour"));

thanks it worked ☺

saroshkhann commented 2 months ago

on chaining promises the neighbour country does not want to appear saying TypeError: Cannot read properties of undefined reading png... i dont know why is that.help please... Screenshot (77)

At line 79 change the code like this: .then(data=> renderCountry(data[0], "neighbour"));

thanks it worked ☺

Always Welcome, Follow me to stay in touch πŸ˜€