-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
25 lines (19 loc) · 901 Bytes
/
Copy pathscript.js
File metadata and controls
25 lines (19 loc) · 901 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const countryContainer = document.querySelector('.countries-container')
fetch('https://restcountries.com/v3.1/all').then((res) => res.json())
.then((data) => {
data.forEach((country) => {
const countryCard = document.createElement('a')
countryCard.href = `/country.html?name=${country.name.common}`
countryCard.classList.add('country-card')
countryCard.innerHTML = `
<img src="${country.flags.svg}" alt="flag">
<div class="card-text">
<h3 class="card-title">${country.name.common}</h3>
<p><b>Population: </b>${country.population.toLocaleString('en-IN')}</p>
<p><b>Region: </b>${country.region}</p>
<p><b>Capital: </b> ${country.capital?.[0]}</p>
</div>
`
countryContainer.append(countryCard)
});
})