From ce99974eb5dea79a33e84614a5938df8843c9934 Mon Sep 17 00:00:00 2001
From: GAJAL999 <112615069+GAJAL999@users.noreply.github.com>
Date: Fri, 18 Oct 2024 00:13:56 +0530
Subject: [PATCH 1/2] Add files via upload
---
currency.js | 161 +++++++++++++++++++++++++++++++++++++++++
currencyconverter.css | 80 ++++++++++++++++++++
currencyconverter.html | 46 ++++++++++++
currencyconverter.js | 59 +++++++++++++++
4 files changed, 346 insertions(+)
create mode 100644 currency.js
create mode 100644 currencyconverter.css
create mode 100644 currencyconverter.html
create mode 100644 currencyconverter.js
diff --git a/currency.js b/currency.js
new file mode 100644
index 0000000..bae8001
--- /dev/null
+++ b/currency.js
@@ -0,0 +1,161 @@
+const countryList = {
+ AED: "AE",
+ AFN: "AF",
+ XCD: "AG",
+ ALL: "AL",
+ AMD: "AM",
+ ANG: "AN",
+ AOA: "AO",
+ AQD: "AQ",
+ ARS: "AR",
+ AUD: "AU",
+ AZN: "AZ",
+ BAM: "BA",
+ BBD: "BB",
+ BDT: "BD",
+ XOF: "BE",
+ BGN: "BG",
+ BHD: "BH",
+ BIF: "BI",
+ BMD: "BM",
+ BND: "BN",
+ BOB: "BO",
+ BRL: "BR",
+ BSD: "BS",
+ NOK: "BV",
+ BWP: "BW",
+ BYR: "BY",
+ BZD: "BZ",
+ CAD: "CA",
+ CDF: "CD",
+ XAF: "CF",
+ CHF: "CH",
+ CLP: "CL",
+ CNY: "CN",
+ COP: "CO",
+ CRC: "CR",
+ CUP: "CU",
+ CVE: "CV",
+ CYP: "CY",
+ CZK: "CZ",
+ DJF: "DJ",
+ DKK: "DK",
+ DOP: "DO",
+ DZD: "DZ",
+ ECS: "EC",
+ EEK: "EE",
+ EGP: "EG",
+ ETB: "ET",
+ EUR: "FR",
+ FJD: "FJ",
+ FKP: "FK",
+ GBP: "GB",
+ GEL: "GE",
+ GGP: "GG",
+ GHS: "GH",
+ GIP: "GI",
+ GMD: "GM",
+ GNF: "GN",
+ GTQ: "GT",
+ GYD: "GY",
+ HKD: "HK",
+ HNL: "HN",
+ HRK: "HR",
+ HTG: "HT",
+ HUF: "HU",
+ IDR: "ID",
+ ILS: "IL",
+ INR: "IN",
+ IQD: "IQ",
+ IRR: "IR",
+ ISK: "IS",
+ JMD: "JM",
+ JOD: "JO",
+ JPY: "JP",
+ KES: "KE",
+ KGS: "KG",
+ KHR: "KH",
+ KMF: "KM",
+ KPW: "KP",
+ KRW: "KR",
+ KWD: "KW",
+ KYD: "KY",
+ KZT: "KZ",
+ LAK: "LA",
+ LBP: "LB",
+ LKR: "LK",
+ LRD: "LR",
+ LSL: "LS",
+ LTL: "LT",
+ LVL: "LV",
+ LYD: "LY",
+ MAD: "MA",
+ MDL: "MD",
+ MGA: "MG",
+ MKD: "MK",
+ MMK: "MM",
+ MNT: "MN",
+ MOP: "MO",
+ MRO: "MR",
+ MTL: "MT",
+ MUR: "MU",
+ MVR: "MV",
+ MWK: "MW",
+ MXN: "MX",
+ MYR: "MY",
+ MZN: "MZ",
+ NAD: "NA",
+ XPF: "NC",
+ NGN: "NG",
+ NIO: "NI",
+ NPR: "NP",
+ NZD: "NZ",
+ OMR: "OM",
+ PAB: "PA",
+ PEN: "PE",
+ PGK: "PG",
+ PHP: "PH",
+ PKR: "PK",
+ PLN: "PL",
+ PYG: "PY",
+ QAR: "QA",
+ RON: "RO",
+ RSD: "RS",
+ RUB: "RU",
+ RWF: "RW",
+ SAR: "SA",
+ SBD: "SB",
+ SCR: "SC",
+ SDG: "SD",
+ SEK: "SE",
+ SGD: "SG",
+ SKK: "SK",
+ SLL: "SL",
+ SOS: "SO",
+ SRD: "SR",
+ STD: "ST",
+ SVC: "SV",
+ SYP: "SY",
+ SZL: "SZ",
+ THB: "TH",
+ TJS: "TJ",
+ TMT: "TM",
+ TND: "TN",
+ TOP: "TO",
+ TRY: "TR",
+ TTD: "TT",
+ TWD: "TW",
+ TZS: "TZ",
+ UAH: "UA",
+ UGX: "UG",
+ USD: "US",
+ UYU: "UY",
+ UZS: "UZ",
+ VEF: "VE",
+ VND: "VN",
+ VUV: "VU",
+ YER: "YE",
+ ZAR: "ZA",
+ ZMK: "ZM",
+ ZWD: "ZW",
+};
\ No newline at end of file
diff --git a/currencyconverter.css b/currencyconverter.css
new file mode 100644
index 0000000..83ae8b8
--- /dev/null
+++ b/currencyconverter.css
@@ -0,0 +1,80 @@
+* {
+ margin: 0;
+ padding: 0;
+ }
+
+ body {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ min-height: 100vh;
+ background-color: #f4e4ba;
+ }
+
+ .container {
+ background-color: #fff;
+ padding: 2rem;
+ border-radius: 1rem;
+ min-height: 45vh;
+ width: 40vh;
+ }
+
+ form {
+ margin: 2rem 0 1rem 0;
+ }
+
+ form select,button,input {
+ width: 100%;
+ border: none;
+ outline: none;
+ border-radius: 0.75rem;
+ }
+
+ form input {
+ border: 1px solid lightgray;
+ font-size: 1rem;
+ height: 3rem;
+ padding-left: 0.5rem;
+ }
+
+ .dropdown {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin-top: 2rem;
+ }
+
+ .dropdown i {
+ font-size: 1.5rem;
+ margin-top: 1rem;
+ }
+
+ .select-container img {
+ max-width: 2rem;
+ }
+
+ .select-container {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ width: 6rem;
+ border-radius: 0.5rem;
+ border: 1px solid lightgray;
+ }
+
+ .select-container select {
+ font-size: 1rem;
+ width: auto;
+ }
+
+ .msg {
+ margin: 2rem 0 2rem 0;
+ }
+
+ form button {
+ height: 3rem;
+ background-color: #af4d98;
+ color: #fff;
+ font-size: 1.15rem;
+ cursor: pointer;
+ }
\ No newline at end of file
diff --git a/currencyconverter.html b/currencyconverter.html
new file mode 100644
index 0000000..805641c
--- /dev/null
+++ b/currencyconverter.html
@@ -0,0 +1,46 @@
+
+
+
+
+
+ Currency Converter
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/currencyconverter.js b/currencyconverter.js
new file mode 100644
index 0000000..e1d644d
--- /dev/null
+++ b/currencyconverter.js
@@ -0,0 +1,59 @@
+const BASE_URL =
+ "https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies";
+
+const dropdowns = document.querySelectorAll(".dropdown select");
+const btn = document.querySelector("form button");
+const fromCurr = document.querySelector(".from select");
+const toCurr = document.querySelector(".to select");
+const msg = document.querySelector(".msg");
+
+for (let select of dropdowns) {
+ for (currCode in countryList) {
+ let newOption = document.createElement("option");
+ newOption.innerText = currCode;
+ newOption.value = currCode;
+ if (select.name === "from" && currCode === "USD") {
+ newOption.selected = "selected";
+ } else if (select.name === "to" && currCode === "INR") {
+ newOption.selected = "selected";
+ }
+ select.append(newOption);
+ }
+
+ select.addEventListener("change", (evt) => {
+ updateFlag(evt.target);
+ });
+}
+
+const updateExchangeRate = async () => {
+ let amount = document.querySelector(".amount input");
+ let amtVal = amount.value;
+ if (amtVal === "" || amtVal < 1) {
+ amtVal = 1;
+ amount.value = "1";
+ }
+ const URL = `${BASE_URL}/${fromCurr.value.toLowerCase()}/${toCurr.value.toLowerCase()}.json`;
+ let response = await fetch(URL);
+ let data = await response.json();
+ let rate = data[toCurr.value.toLowerCase()];
+
+ let finalAmount = amtVal * rate;
+ msg.innerText = `${amtVal} ${fromCurr.value} = ${finalAmount} ${toCurr.value}`;
+};
+
+const updateFlag = (element) => {
+ let currCode = element.value;
+ let countryCode = countryList[currCode];
+ let newSrc = `https://flagsapi.com/${countryCode}/flat/64.png`;
+ let img = element.parentElement.querySelector("img");
+ img.src = newSrc;
+};
+
+btn.addEventListener("click", (evt) => {
+ evt.preventDefault();
+ updateExchangeRate();
+});
+
+window.addEventListener("load", () => {
+ updateExchangeRate();
+});
\ No newline at end of file
From f4bda11b99bcc23d7a769025bc7be9a8fbac92f9 Mon Sep 17 00:00:00 2001
From: GAJAL999 <112615069+GAJAL999@users.noreply.github.com>
Date: Fri, 18 Oct 2024 00:17:11 +0530
Subject: [PATCH 2/2] Add files via upload
---
currency converter/currency.js | 161 ++++++++++++++++++++++
currency converter/currencyconverter.css | 80 +++++++++++
currency converter/currencyconverter.html | 46 +++++++
currency converter/currencyconverter.js | 59 ++++++++
4 files changed, 346 insertions(+)
create mode 100644 currency converter/currency.js
create mode 100644 currency converter/currencyconverter.css
create mode 100644 currency converter/currencyconverter.html
create mode 100644 currency converter/currencyconverter.js
diff --git a/currency converter/currency.js b/currency converter/currency.js
new file mode 100644
index 0000000..bae8001
--- /dev/null
+++ b/currency converter/currency.js
@@ -0,0 +1,161 @@
+const countryList = {
+ AED: "AE",
+ AFN: "AF",
+ XCD: "AG",
+ ALL: "AL",
+ AMD: "AM",
+ ANG: "AN",
+ AOA: "AO",
+ AQD: "AQ",
+ ARS: "AR",
+ AUD: "AU",
+ AZN: "AZ",
+ BAM: "BA",
+ BBD: "BB",
+ BDT: "BD",
+ XOF: "BE",
+ BGN: "BG",
+ BHD: "BH",
+ BIF: "BI",
+ BMD: "BM",
+ BND: "BN",
+ BOB: "BO",
+ BRL: "BR",
+ BSD: "BS",
+ NOK: "BV",
+ BWP: "BW",
+ BYR: "BY",
+ BZD: "BZ",
+ CAD: "CA",
+ CDF: "CD",
+ XAF: "CF",
+ CHF: "CH",
+ CLP: "CL",
+ CNY: "CN",
+ COP: "CO",
+ CRC: "CR",
+ CUP: "CU",
+ CVE: "CV",
+ CYP: "CY",
+ CZK: "CZ",
+ DJF: "DJ",
+ DKK: "DK",
+ DOP: "DO",
+ DZD: "DZ",
+ ECS: "EC",
+ EEK: "EE",
+ EGP: "EG",
+ ETB: "ET",
+ EUR: "FR",
+ FJD: "FJ",
+ FKP: "FK",
+ GBP: "GB",
+ GEL: "GE",
+ GGP: "GG",
+ GHS: "GH",
+ GIP: "GI",
+ GMD: "GM",
+ GNF: "GN",
+ GTQ: "GT",
+ GYD: "GY",
+ HKD: "HK",
+ HNL: "HN",
+ HRK: "HR",
+ HTG: "HT",
+ HUF: "HU",
+ IDR: "ID",
+ ILS: "IL",
+ INR: "IN",
+ IQD: "IQ",
+ IRR: "IR",
+ ISK: "IS",
+ JMD: "JM",
+ JOD: "JO",
+ JPY: "JP",
+ KES: "KE",
+ KGS: "KG",
+ KHR: "KH",
+ KMF: "KM",
+ KPW: "KP",
+ KRW: "KR",
+ KWD: "KW",
+ KYD: "KY",
+ KZT: "KZ",
+ LAK: "LA",
+ LBP: "LB",
+ LKR: "LK",
+ LRD: "LR",
+ LSL: "LS",
+ LTL: "LT",
+ LVL: "LV",
+ LYD: "LY",
+ MAD: "MA",
+ MDL: "MD",
+ MGA: "MG",
+ MKD: "MK",
+ MMK: "MM",
+ MNT: "MN",
+ MOP: "MO",
+ MRO: "MR",
+ MTL: "MT",
+ MUR: "MU",
+ MVR: "MV",
+ MWK: "MW",
+ MXN: "MX",
+ MYR: "MY",
+ MZN: "MZ",
+ NAD: "NA",
+ XPF: "NC",
+ NGN: "NG",
+ NIO: "NI",
+ NPR: "NP",
+ NZD: "NZ",
+ OMR: "OM",
+ PAB: "PA",
+ PEN: "PE",
+ PGK: "PG",
+ PHP: "PH",
+ PKR: "PK",
+ PLN: "PL",
+ PYG: "PY",
+ QAR: "QA",
+ RON: "RO",
+ RSD: "RS",
+ RUB: "RU",
+ RWF: "RW",
+ SAR: "SA",
+ SBD: "SB",
+ SCR: "SC",
+ SDG: "SD",
+ SEK: "SE",
+ SGD: "SG",
+ SKK: "SK",
+ SLL: "SL",
+ SOS: "SO",
+ SRD: "SR",
+ STD: "ST",
+ SVC: "SV",
+ SYP: "SY",
+ SZL: "SZ",
+ THB: "TH",
+ TJS: "TJ",
+ TMT: "TM",
+ TND: "TN",
+ TOP: "TO",
+ TRY: "TR",
+ TTD: "TT",
+ TWD: "TW",
+ TZS: "TZ",
+ UAH: "UA",
+ UGX: "UG",
+ USD: "US",
+ UYU: "UY",
+ UZS: "UZ",
+ VEF: "VE",
+ VND: "VN",
+ VUV: "VU",
+ YER: "YE",
+ ZAR: "ZA",
+ ZMK: "ZM",
+ ZWD: "ZW",
+};
\ No newline at end of file
diff --git a/currency converter/currencyconverter.css b/currency converter/currencyconverter.css
new file mode 100644
index 0000000..83ae8b8
--- /dev/null
+++ b/currency converter/currencyconverter.css
@@ -0,0 +1,80 @@
+* {
+ margin: 0;
+ padding: 0;
+ }
+
+ body {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ min-height: 100vh;
+ background-color: #f4e4ba;
+ }
+
+ .container {
+ background-color: #fff;
+ padding: 2rem;
+ border-radius: 1rem;
+ min-height: 45vh;
+ width: 40vh;
+ }
+
+ form {
+ margin: 2rem 0 1rem 0;
+ }
+
+ form select,button,input {
+ width: 100%;
+ border: none;
+ outline: none;
+ border-radius: 0.75rem;
+ }
+
+ form input {
+ border: 1px solid lightgray;
+ font-size: 1rem;
+ height: 3rem;
+ padding-left: 0.5rem;
+ }
+
+ .dropdown {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin-top: 2rem;
+ }
+
+ .dropdown i {
+ font-size: 1.5rem;
+ margin-top: 1rem;
+ }
+
+ .select-container img {
+ max-width: 2rem;
+ }
+
+ .select-container {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ width: 6rem;
+ border-radius: 0.5rem;
+ border: 1px solid lightgray;
+ }
+
+ .select-container select {
+ font-size: 1rem;
+ width: auto;
+ }
+
+ .msg {
+ margin: 2rem 0 2rem 0;
+ }
+
+ form button {
+ height: 3rem;
+ background-color: #af4d98;
+ color: #fff;
+ font-size: 1.15rem;
+ cursor: pointer;
+ }
\ No newline at end of file
diff --git a/currency converter/currencyconverter.html b/currency converter/currencyconverter.html
new file mode 100644
index 0000000..805641c
--- /dev/null
+++ b/currency converter/currencyconverter.html
@@ -0,0 +1,46 @@
+
+
+
+
+
+ Currency Converter
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/currency converter/currencyconverter.js b/currency converter/currencyconverter.js
new file mode 100644
index 0000000..e1d644d
--- /dev/null
+++ b/currency converter/currencyconverter.js
@@ -0,0 +1,59 @@
+const BASE_URL =
+ "https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies";
+
+const dropdowns = document.querySelectorAll(".dropdown select");
+const btn = document.querySelector("form button");
+const fromCurr = document.querySelector(".from select");
+const toCurr = document.querySelector(".to select");
+const msg = document.querySelector(".msg");
+
+for (let select of dropdowns) {
+ for (currCode in countryList) {
+ let newOption = document.createElement("option");
+ newOption.innerText = currCode;
+ newOption.value = currCode;
+ if (select.name === "from" && currCode === "USD") {
+ newOption.selected = "selected";
+ } else if (select.name === "to" && currCode === "INR") {
+ newOption.selected = "selected";
+ }
+ select.append(newOption);
+ }
+
+ select.addEventListener("change", (evt) => {
+ updateFlag(evt.target);
+ });
+}
+
+const updateExchangeRate = async () => {
+ let amount = document.querySelector(".amount input");
+ let amtVal = amount.value;
+ if (amtVal === "" || amtVal < 1) {
+ amtVal = 1;
+ amount.value = "1";
+ }
+ const URL = `${BASE_URL}/${fromCurr.value.toLowerCase()}/${toCurr.value.toLowerCase()}.json`;
+ let response = await fetch(URL);
+ let data = await response.json();
+ let rate = data[toCurr.value.toLowerCase()];
+
+ let finalAmount = amtVal * rate;
+ msg.innerText = `${amtVal} ${fromCurr.value} = ${finalAmount} ${toCurr.value}`;
+};
+
+const updateFlag = (element) => {
+ let currCode = element.value;
+ let countryCode = countryList[currCode];
+ let newSrc = `https://flagsapi.com/${countryCode}/flat/64.png`;
+ let img = element.parentElement.querySelector("img");
+ img.src = newSrc;
+};
+
+btn.addEventListener("click", (evt) => {
+ evt.preventDefault();
+ updateExchangeRate();
+});
+
+window.addEventListener("load", () => {
+ updateExchangeRate();
+});
\ No newline at end of file