Question:
I am trying to get the latest exchange rate from in in my repl. I then try to display it in my front-end. I get an error in the console TypeError. The network tab has the correct response of the API. I’m not sure what’s happening here.
Current behavior:
TypeError
Desired behavior
Show the latest exchange rate
Repl link:
https://replit.com/@SehjKashyap/CurrencyConverter#script.js
code snippet
function updateExchangeRate() {
fetch('https://api.exchangerate-api.com/v4/latest/USD')
.then(response => response.json())
.then(data => {
exchangeRate = data.rates.INR;
document.getElementById('currentExchangeRate').innerText = exchangeRate;
console.log('Exchange rate updated:', exchangeRate);
})
.catch(error => {
console.error('Error fetching exchange rate:', error);
document.getElementById('currentExchangeRate').innerText = 'Error fetching rate';
});
}