Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 11 additions & 23 deletions demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,17 @@ async function fetchData(url) {
}
}

//function to convert any currency to INR using a fixed exchange ratefunction, intentioanally add cognitive complexity by using multiple if-else statements
//function to convert any currency to INR using a fixed exchange rate function
function convertToINR(amount, currency) {
let exchangeRate;
if (currency === 'USD') {
exchangeRate = 74.85;
} else if (currency === 'EUR') {
exchangeRate = 88.50;
} else if (currency === 'GBP') {
exchangeRate = 103.25;
} else if (currency === 'JPY') {
exchangeRate = 0.68;
} else if (currency === 'AUD') {
exchangeRate = 55.30;
} else if (currency === 'CAD') {
exchangeRate = 59.20;
} else if (currency === 'CHF') {
exchangeRate = 82.10;
} else if (currency === 'CNY') {
exchangeRate = 11.50;
} else if (currency === 'HKD') {
exchangeRate = 9.60;
} else {
const exchangeRates = {
USD: 74.85,
EUR: 88.50,
GBP: 103.20,
JPY: 0.68
};
if (Object.hasOwn(exchangeRates, currency)) {
return amount * exchangeRates[currency];
} else {
throw new Error('Unsupported currency');
}
return amount * exchangeRate;
}
}