Hello,
I’m working through the ‘Getting Started with Velo’ exercises and I cannot get the currency converter to work.
My code is as follows.
import { getJSON } from ‘wix-fetch’ ;
const url = “https://api.exchangeratesapi.io/latest” ;
let currencyOptions = [
{ “value” : “USD” , “label” : “US Dollars” },
{ “value” : “EUR” , “label” : “Euros” },
{ “value” : “JPY” , “label” : “Japanese Yen” },
]
$w . onReady ( function () {
populateDropdowns ();
$w ( ‘#calculateButton’ ). onClick (( event ) => {
calculateCurrency ();
})
});
function populateDropdowns () {
$w ( ‘Dropdown’ ). options = currencyOptions ;
$w ( ‘Dropdown’ ). selectedIndex = 0 ;
}
function calculateCurrency () {
let initialAmount = $w ( “#sourceAmount” ). value ;
let sourceSymbol = $w ( “#sourceCurrency” ). value ;
let targetSymbol = $w ( “#targetCurrency” ). value ;
let fullUrl = ${ url } ?base= ${ sourceSymbol } &symbols= ${ targetSymbol }
;
getJSON ( fullUrl )
. then ( json => {
$w ( “#targetAmount” ). value = initialAmount * json . rates [ targetSymbol ];
})
}
I have carefully named all of the elements as shown in the tutorial and double checked many times.
The console log in Chrome AND Wix’s Site Events say " Uncaught (in promise) TypeError: Cannot read property ‘JPY’ of undefined"
It is the same for USD and EUR. When I hove over “#targetAmount” it tells me that you cannot convert numbers to strings.
I’m really lost and even when I copy and paste the code it doesn’t work. The console log is telling me the error is on line 30. Any and all help is greatly appreciated.
Thank you!