function convertCurrency() {
// Get the amount and currencies from the form const amount = document.querySelector("input[name=amount]").value; const fromCurrency = document.querySelector("select[name=from-currency]").value; const toCurrency = document.querySelector("select[name=to-currency]").value;
// Make an API request to get the exchange rate axios.get(`https://api.exchangerate-api.com/v4/latest/${fromCurrency}`) .then((response) => {
// Get the exchange rate const rate = response.data.rates[toCurrency];
// Calculate the converted amount const convertedAmount = amount * rate;
// Update the result field document.querySelector("input[name=result]").value = convertedAmount;
}) .catch((error) => {
// Handle errors console.log(error);
});
}
// Add an event listener to the convert button document.querySelector("button[type=submit]").addEventListener("click", convertCurrency);