This repository was archived by the owner on Apr 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
60 lines (50 loc) · 1.99 KB
/
app.js
File metadata and controls
60 lines (50 loc) · 1.99 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* Author: Al Nahian (alnahian2003)
* Author URI: https://alnahian2003.github.io
* Project Name: Flagma
* Project Type: Country Flags, Country Informations, API Integrations, Intermediate JavaScript Project etc.
* Get In Touch:
* https://alnahian2003.github.io
* https://github.com/alnahian2003
* https://facebook.com/alnahian2003
* https://twitter.com/alnahian2003
* https://behance.net/alnahian2003
* mail me at: a.alnahian2003@gmail.com
*/
const topBarTitle = document.getElementById("totalCountries");
topBarTitle.innerText = "Total " + countries.length + " Countries";
// Display All The Countries Name and Flag
const flagContainer = document.getElementById("flags");
function displayFlags() {
const len = countries.length;
for (let i = 0; i < len; i++) {
// Create a Div with class flag
const flagDiv = document.createElement("div");
flagDiv.className = "flag";
// Create an Img Element for Showing Flags Image
const flagImg = document.createElement("img");
flagImg.className = "flag-img";
flagImg.alt = countries[i].name;
//convert country code to lowercase to meet the exact filepath name
let lowr = countries[i].code;
flagImg.src = "./flags/" + lowr.toLowerCase() + ".svg";
// Append the Img to the flagDiv
flagDiv.appendChild(flagImg);
flagContainer.appendChild(flagDiv);
// Create h4 Element for the Country Name
const countryName = document.createElement("h4");
countryName.className = "country-name";
countryName.innerText = countries[i].name;
flagDiv.appendChild(countryName);
// Create p Element for the Country Code
const countryCode = document.createElement("p");
countryCode.className = "country-code";
countryCode.innerHTML = "<span>Country Code:</span> " + countries[i].code;
flagDiv.appendChild(countryCode);
}
}
displayFlags();
// Footer Dynamic Year
const yearContainer = document.getElementById("year");
let currentYear = new Date();
yearContainer.innerText = currentYear.getFullYear();