-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
112 lines (110 loc) · 3.86 KB
/
index.html
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Random Country Generator</title>
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN"
crossorigin="anonymous"
/>
</head>
<body>
<div
style="
width: 100%;
height: 100vh;
background-image: url(./pexels-pixabay-41949.jpg);
"
>
<div id="" class="w-50 mx-auto text-center pt-5">
<h1 class="text-light">All About Countries</h1>
<button onclick="randomCountryGenerator()" class="btn btn-success">
Generate Country 🔍
</button>
<div id="result" class="mt-3"></div>
</div>
</div>
</body>
<script>
const randomCountryGenerator = async () => {
const response = await fetch("https://restcountries.com/v3.1/all");
const countryDetails = await response.json();
const country =
countryDetails[Math.floor(Math.random() * countryDetails.length)];
const flag = country.flags.png;
const cname = country.name.common;
const capital = country.capital;
const population = country.population;
const timezones = country.timezones.join(", ");
const continents = country.continents.join(", ");
const languages = Object.values(country.languages).join(", ");
const currencies = Object.values(country.currencies);
const currencyName = currencies[0].name;
const currencySymbol = currencies[0].symbol;
const gmap = country.maps.googleMaps;
result.innerHTML = `
<div
class="card mx-auto mt-3 p-2 border-light text-light"
style="
width: auto;
background: transparent;
backdrop-filter: blur(5px);">
<h5 class="card-title fs-3 fw-bold">${cname}</h5>
<div class="row g-0">
<div class="col-6">
<img src="${flag}" class="img-fluid mt-4" alt="..." />
</div>
<div class="col-6">
<div class="card-body">
<ul class="list-group list-group-flush text-start">
<li
class="list-group-item text-light fw-bold"
style="background: transparent"
>
Capital: ${capital}
</li>
<li
class="list-group-item text-light fw-bold"
style="background: transparent"
>
Population: ${population}
</li>
<li
class="list-group-item text-light fw-bold"
style="background: transparent"
>
Timezone(s): ${timezones}
</li>
<li
class="list-group-item text-light fw-bold"
style="background: transparent"
>
Continent(s): ${continents}
</li>
<li
class="list-group-item text-light fw-bold"
style="background: transparent"
>
Currency: ${currencySymbol}, ${currencyName}
</li>
<li
class="list-group-item text-light fw-bold"
style="background: transparent"
>
Languages: ${languages}
</li>
</ul>
</div>
</div>
<a href="${gmap}" class="btn btn-primary w-25 mx-auto pt-1">
View on Google Map
</a>
</div>
</div>
`;
};
</script>
</html>