Currency Exchange WidgetDisplays currency exchange rates and conversions
function convertCurrency(from, to, amount) {
// Your currency conversion logic here
// Replace this example with your own implementation
var convertedAmount = amount * 1.5;
return convertedAmount;
}
function displayExchangeRates() {
var baseCurrency = 'USD'; // Set your base currency
var amount = 100; // Set your amount
// Fetch exchange rates using an API
// Replace 'YOUR_API_URL' with the actual API URL
var apiUrl = 'https://techpital-ng.blogspot.com';
// Make an AJAX request to fetch exchange rates
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
var exchangeRates = JSON.parse(xhr.responseText);
// Iterate through the exchange rates and display conversions
for (var currency in exchangeRates.rates) {
if (exchangeRates.rates.hasOwnProperty(currency)) {
var convertedAmount = convertCurrency(baseCurrency, currency, amount);
var result = amount + ' ' + baseCurrency + ' is equal to ' + convertedAmount + ' ' + currency + '.';
document.getElementById('exchange-rates').innerHTML += '
' + result + '
';
}
}
}
};
xhr.open('GET', apiUrl, true);
xhr.send();
}
// Call the function when the page loads
window.onload = function() {
displayExchangeRates();
};
]]>