Add complete project
This commit is contained in:
parent
c449843941
commit
76725c3410
8 changed files with 144 additions and 0 deletions
11
js/continent.js
Normal file
11
js/continent.js
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
const continentCode = new URLSearchParams(window.location.search).get("code");
|
||||
const countryList = document.getElementById("country-list");
|
||||
fetch("https://countries.trevorblades.com/", { "method": "POST", "body": JSON.stringify({ query: "query continent($code: ID!) { continent(code: $code) { name countries { name code }}}", "operationName": "continent", "variables": { "code": continentCode }}), headers: { "Content-Type": "application/json" } }).then(response => response.json()).then(({data}) => {
|
||||
document.getElementById("continent-heading").innerText = data.continent.name;
|
||||
const countries = data.continent.countries;
|
||||
for (const country of countries) {
|
||||
const newListItem = document.createElement("li");
|
||||
newListItem.innerHTML = `<a href="/country.html?code=${country.code}"> ${country.name} </a>`;
|
||||
countryList.append(newListItem);
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue