complete-javascript-course icon indicating copy to clipboard operation
complete-javascript-course copied to clipboard

Country API Issues while rendering (Complete Solution)

Open saroshkhann opened this issue 1 year ago • 4 comments

////// 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);

saroshkhann avatar Sep 05 '24 10:09 saroshkhann

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)

InnocentCode4ui avatar Sep 06 '24 09:09 InnocentCode4ui

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"));

saroshkhann avatar Sep 06 '24 09:09 saroshkhann

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 ☺

InnocentCode4ui avatar Sep 06 '24 10:09 InnocentCode4ui

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 😀

saroshkhann avatar Sep 06 '24 10:09 saroshkhann