This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const convertCurrencyAlt = async (from, to, amount) => { | |
const countries = await getCountriesAlt(to) | |
const rate = await getExchangeRateAlt(from, to) | |
const exchangedAmount = amount * rate | |
return `${amount} ${from} is worth ${exchangedAmount} ${to}. ${to} can be used in the following countries: ${countries.join(', ')}` | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const convertCurrency = (from, to, amount) => { | |
let countries | |
return getCountries(to).then((tempCountries) => { | |
countries = tempCountries | |
return getExchangeRate(from, to) | |
}).then((rate) => { | |
const exchangedAmount = amount * rate | |
return `${amount} ${from} is worth ${exchangedAmount} ${to}. ${to} can be used in the following countries: ${countries.join(', ')}` | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getCountries = (currencyCode) => { | |
return axios.get(`https://restcountries.eu/rest/v2/currency/${currencyCode}`).then((res)=> { | |
return res.data.map((country)=> country.name) | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getExchangeRate = (from, to) => { | |
return axios.get(`http://api.fixer.io/latest?base=${from}`).then((res)=> { | |
return res.data.rates[to] | |
}) | |
} |
NewerOlder