Conversion result will appear here
Amount: ${amount} ${fromCurrency}
Exchange Rate: 1 ${fromCurrency} = ${rate} ${toCurrency}
Converted Amount: ${result.toFixed(2)} ${toCurrency}
`;
document.querySelector('.result-details').innerHTML = resultDetails;
} catch (error) {
console.error('Error:', error);
document.getElementById('conversion-result').innerText = 'An error occurred. Please try again.';
}
}
// Initialize the flags in the dropdowns
document.addEventListener('DOMContentLoaded', function() {
updateFlag(document.getElementById('from-currency'));
updateFlag(document.getElementById('to-currency'));
});