This is the simple currency converter script which gets the currency rate from JS library - it's based on the last value in JSON chaining (PLN, EUR etc. ) ->
var priceAmount = amount;
var currencyRateUSDPLN = Currency.rates.PLN;
I know that I can't pass the function argument straight to Currency.rates.PLN, what is the shortest way to achieve this functionality ?
function convertCurrency (amount, to) {
var priceAmount = amount;
// here I want to pass 'to' argument (EUR, PLN for example)
var currencyRateUSDPLN = Currency.rates.to;
var pricePLN = ( priceAmount / currencyRateUSDPLN ).toFixed(2);
console.log(pricePLN + ' PLN');
}
The Currency object contains -> link
Currency.rates.PLN?Currency.ratescontains, there's not much we can help with, but shouldn'tvar currencyRateUSDPLN = Currency.rates.to;just bevar currencyRateUSDPLN = to;as you'd be passing theCurrency.rates.PLN;to the function?