Compare commits

...

1 commit

Author SHA1 Message Date
76725c3410 Add complete project 2025-11-19 23:24:55 +01:00
8 changed files with 144 additions and 0 deletions

18
continent.html Normal file
View file

@ -0,0 +1,18 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Continent - World Information System</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1 id="continent-heading"></h1>
<div>
<ul id="country-list">
</ul>
</div>
</body>
<script src="js/continent.js"></script>
</html>

18
continents.html Normal file
View file

@ -0,0 +1,18 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>All Continents - World Information System</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>All continents</h1>
<div>
<ul id="continent-list">
</ul>
</div>
</body>
<script src="js/continents.js"></script>
</html>

34
country.html Normal file
View file

@ -0,0 +1,34 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Country - World Information System</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<div>
<h1 id="country-heading"></h1>
</div>
<h2 id="country-capital"></h2>
<h2>Languages</h2>
<div>
<ul id="language-list">
</ul>
</div>
<h2>Currencies</h2>
<div>
<ul id="currency-list">
</li>
</ul>
</div>
<h2>Phone Prefix</h2>
<div>
<ul id="phone-prefix-list">
</ul>
</div>
<h2>Flag</h2>
<span style="font-size: xxx-large" id="flag-symbol"></span>
</body>
<script src="js/country.js"></script>
</html>

18
currency.html Normal file
View file

@ -0,0 +1,18 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Countries paying in - World Information System</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>Countries paying in <span id="currency"></span></h1>
<div>
<ul id="country-list">
</ul>
</div>
</body>
<script src="js/currency.js"></script>
</html>

11
js/continent.js Normal file
View 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);
}
});

10
js/continents.js Normal file
View file

@ -0,0 +1,10 @@
const continentList = document.getElementById("continent-list");
fetch("https://countries.trevorblades.com/", { method: "POST", body: JSON.stringify({"query":"query allContinents { continents { name code }}","operationName":"allContinents"}), headers: { "Content-Type": "application/json" } }).then(response => response.json()).then(({data}) => {
const continents = data.continents;
document.getElementById("")
for (const continent of continents) {
const newListItem = document.createElement("li");
newListItem.innerHTML = `<a href="/continent.html?code=${continent.code}"> ${continent.name} </a>`;
continentList.append(newListItem);
}
});

24
js/country.js Normal file
View file

@ -0,0 +1,24 @@
const countryCode = new URLSearchParams(window.location.search).get("code");
const languageList = document.getElementById("language-list");
const currencyList = document.getElementById("currency-list")
const phonePrefixList = document.getElementById("phone-prefix-list")
fetch("https://countries.trevorblades.com/", { "method": "POST", "body": JSON.stringify({ query: "query country($code: ID!) { country(code: $code) { name capital phones currencies languages { name native } emoji }}", "operationName": "country", "variables": { "code": countryCode }}), headers: { "Content-Type": "application/json" } }).then(response => response.json()).then(({data}) => {
document.getElementById("country-heading").innerText = data.country.name;
document.getElementById("country-capital").innerText = data.country.capital;
document.getElementById("flag-symbol").innerText = data.country.emoji;
for (const language of data.country.languages) {
const newListItem = document.createElement("li");
newListItem.innerText = language.name;
languageList.append(newListItem);
}
for (const currency of data.country.currencies) {
const newListItem = document.createElement("li");
newListItem.innerHTML = `<a href="/currency.html?currency=${currency}">${currency}</a>`;
currencyList.append(newListItem);
}
for (const phonePrefix of data.country.phones) {
const newListItem = document.createElement("li");
newListItem.innerText = `+${phonePrefix}`;
phonePrefixList.append(newListItem);
}
});

11
js/currency.js Normal file
View file

@ -0,0 +1,11 @@
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);
}
});