Skip to content

Commit ce368dc

Browse files
committed
test coginitive complexity
1 parent e0b154b commit ce368dc

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

demo.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,31 @@ async function fetchData(url) {
2121
} catch (error) {
2222
console.error('Error fetching data:', error);
2323
}
24+
}
25+
26+
//function to convert any currency to INR using a fixed exchange ratefunction, intentioanally add cognitive complexity by using multiple if-else statements
27+
function convertToINR(amount, currency) {
28+
let exchangeRate;
29+
if (currency === 'USD') {
30+
exchangeRate = 74.85;
31+
} else if (currency === 'EUR') {
32+
exchangeRate = 88.50;
33+
} else if (currency === 'GBP') {
34+
exchangeRate = 103.25;
35+
} else if (currency === 'JPY') {
36+
exchangeRate = 0.68;
37+
} else if (currency === 'AUD') {
38+
exchangeRate = 55.30;
39+
} else if (currency === 'CAD') {
40+
exchangeRate = 59.20;
41+
} else if (currency === 'CHF') {
42+
exchangeRate = 82.10;
43+
} else if (currency === 'CNY') {
44+
exchangeRate = 11.50;
45+
} else if (currency === 'HKD') {
46+
exchangeRate = 9.60;
47+
} else {
48+
throw new Error('Unsupported currency');
49+
}
50+
return amount * exchangeRate;
2451
}

0 commit comments

Comments
 (0)