-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
32 lines (27 loc) · 1.1 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
'use strict';
const btn = document.querySelector('.btn-country');
const countriesContainer = document.querySelector('.countries');
///////////////////////////////////////
const request = new XMLHttpRequest();
request.open('GET', 'https://restcountries.com/v2/name/India');
request.send();
console.log(request.responseText)
request.addEventListener('load', function(){
const dataComplete = JSON.parse(this.responseText);
const data = dataComplete[1];
console.log(data);
const html = `
<article class="country">
<img class="country__img" src="${data.flag}" />
<div class="country__data">
<h3 class="country__name">${data.name}</h3>
<h4 class="country__region">${data.region}</h4>
<p class="country__row"><span>👫</span>${(+data.population /1000000000).toFixed(2) } B</p>
<p class="country__row"><span>🗣️</span>${data.languages[0].nativeName}</p>
<p class="country__row"><span>💰</span>${data.currencies[0].symbol}</p>
</div>
</article>
`;
countriesContainer.insertAdjacentHTML('beforeend', html);
countriesContainer.style.opacity = 1;
})