-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
33 lines (23 loc) · 915 Bytes
/
script.js
File metadata and controls
33 lines (23 loc) · 915 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
25
26
27
28
29
30
31
32
fetch('countries.json')
.then(data => data.json() )
.then(json => {
console.log(json)
// sort an array of countries by comparing area
let sorted = json.sort((a,b) => a.area - b.area );
sorted.forEach( country => {
// dynamically construct a url for a flag
// based on the ISO code.
// https://github.com/mledoze/countries
//
let flagImage = `https://raw.githubusercontent.com/mledoze/countries/master/data/${country.cca3.toLowerCase()}.svg`
// make a div to hold each planet
let div = document.createElement('div')
div.classList.add('country')
div.innerHTML =
`<img class="flag" src="${flagImage}">
<h4>${country.name.common}</h4>
<p>${country.area} km²</p>
<p><b>Lat/Lng</b> ${country.latlng[0]}°,${country.latlng[1]}°</p> `
document.querySelector('#countries') .appendChild(div)
})
})