Currency Converter

United States Dollar (USD) Euro (EUR) Japanese Yen (JPY) British Pound (GBP) Australian Dollar (AUD) Canadian Dollar (CAD) Swiss Franc (CHF) Chinese Yuan (CNY) Indian Rupee (INR) Pakistani Rupee (PKR) Iranian Rial (IRR) Brazilian Real (BRL) Russian Ruble (RUB) South African Rand (ZAR) New Zealand Dollar (NZD) Singapore Dollar (SGD) Hong Kong Dollar (HKD) Norwegian Krone (NOK) Swedish Krona (SEK) Mexican Peso (MXN) Polish Zloty (PLN) Thai Baht (THB) Turkish Lira (TRY) United Arab Emirates Dirham (AED) Qatari Rial (QAR) Indonesian Rupiah (IDR) Philippine Peso (PHP) Israeli New Shekel (ILS) Hungarian Forint (HUF) Czech Koruna (CZK) Chilean Peso (CLP) Colombian Peso (COP) Peruvian Sol (PEN) Romanian Leu (RON) Argentine Peso (ARS) New Taiwan Dollar (TWD) Thai Baht (THB) Bahraini Dinar (BHD) Kuwaiti Dinar (KWD) to United States Dollar (USD) Euro (EUR) Japanese Yen (JPY) British Pound (GBP) Australian Dollar (AUD) Canadian Dollar (CAD) Swiss Franc (CHF) Chinese Yuan (CNY) Indian Rupee (INR) Pakistani Rupee (PKR) Iranian Rial (IRR) Brazilian Real (BRL) Russian Ruble (RUB) South African Rand (ZAR) New Zealand Dollar (NZD) Singapore Dollar (SGD) Hong Kong Dollar (HKD) Norwegian Krone (NOK) Swedish Krona (SEK) Mexican Peso (MXN) Polish Zloty (PLN) Thai Baht (THB) Turkish Lira (TRY) United Arab Emirates Dirham (AED) Qatari Rial (QAR) Indonesian Rupiah (IDR) Philippine Peso (PHP) Israeli New Shekel (ILS) Hungarian Forint (HUF) Czech Koruna (CZK) Chilean Peso (CLP) Colombian Peso (COP) Peruvian Sol (PEN) Romanian Leu (RON) Argentine Peso (ARS) New Taiwan Dollar (TWD) Bahraini Dinar (BHD) Kuwaiti Dinar (KWD)
.currency-converter { text-align: center; margin: 20px auto; background-color: white; padding: 20px; border-radius: 10px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.2); width: 300px; } input, select { margin: 10px 0; padding: 10px; width: 100%; font-size: 16px; } button { padding: 10px; font-size: 16px; background-color: #E22554; color: white; border: none; border-radius: 5px; cursor: pointer; } button:hover { background-color: gray; } .result-display { margin-top: 15px; font-size: 18px; color: #333; } document.getElementById('convert-button').addEventListener('click', function() { const amount = document.getElementById('amount').value; const fromCurrency = document.getElementById('from-currency').value; const toCurrency = document.getElementById('to-currency').value; if (amount === '' || isNaN(amount)) { alert('Please enter a valid amount.'); return; } const url = `https://api.exchangerate-api.com/v4/latest/${fromCurrency}`; fetch(url) .then(response => response.json()) .then(data => { const rate = data.rates[toCurrency]; const convertedAmount = (amount * rate).toFixed(2); document.getElementById('result').innerText = `${amount} ${fromCurrency} = ${convertedAmount} ${toCurrency}`; }) .catch(error => { console.error('Error fetching exchange rates:', error); document.getElementById('result').innerText = 'Error fetching exchange rates. Please try again.'; }); });