From c3dac689a85a71eeae15ef8a624535ee51231ee3 Mon Sep 17 00:00:00 2001 From: Nima Mohajeri Date: Wed, 13 Mar 2024 15:08:17 -0700 Subject: [PATCH] Fix: if country is not found in function, default to USD I forgot that there was this continent called EUROPE and that they had the same currency, so I have to change my logic soon. tbd --- src/functions/countryToCurrency.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/functions/countryToCurrency.js b/src/functions/countryToCurrency.js index 13f7b2a..f4808fa 100644 --- a/src/functions/countryToCurrency.js +++ b/src/functions/countryToCurrency.js @@ -1,8 +1,13 @@ import currencyData from '../api/currencies.json' export function countryToCurrency(countryCode) { + let printedCurr = '' let matchedCurrency = Object.values(currencyData).find((c) => c.code.slice(0, 2) === countryCode) - let printedCurr = `${matchedCurrency.symbol_native} ${matchedCurrency.code}` + if (!matchedCurrency) { + printedCurr = '$ USD' + } else { + printedCurr = `${matchedCurrency.symbol_native} ${matchedCurrency.code}` + } return printedCurr }