-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
26 lines (22 loc) · 1.11 KB
/
app.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
const countryContainer = document.querySelector('.countries-container')
fetch('https://restcountries.com/v3.1/all').then((res) => res.json())
.then((data) => {
data.forEach((country) => {
console.log(country)
const countryCard = document.createElement('a')
countryCard.classList.add('country-card')
countryCard.href = `./country.html?name=${country.name.common}`
const cardHTML = `
<img src="${country.flags.svg}" alt="flag">
<div class="card-text">
<h3>${country.name.common}</h3>
<p><b>Population: </b>${country.population.toLocaleString()}</p>
<p><b>Region: </b>${country.region}</p>
<p><b>Capital: </b>${country.capital}</p>
<p><b>Language: </b>${Object.values(country.languages)[0]}</p>
</div>
`
countryCard.innerHTML = cardHTML
countryContainer.appendChild(countryCard)
})
})