11 lines
No EOL
883 B
JavaScript
11 lines
No EOL
883 B
JavaScript
const currency = new URLSearchParams(window.location.search).get("currency");
|
|
const countryList = document.getElementById("country-list");
|
|
fetch("https://countries.trevorblades.com/", { "method": "POST", "body": JSON.stringify({ query: "query countriesPayingIn($currency: [String!]!) {countries(filter: {currency: {in:$currency}}) { name code }}", "operationName": "countriesPayingIn", "variables": { "currency": currency } }), headers: { "Content-Type": "application/json" } }).then(response => response.json()).then(({ data }) => {
|
|
document.getElementById("currency").innerText = currency;
|
|
const countries = data.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);
|
|
}
|
|
}); |