-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththirdChallenge.js
71 lines (55 loc) · 1.84 KB
/
thirdChallenge.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function calculateNetSalary (salary, benefits){
//list paye, nhif and nssf deductions
//calculate paye
const calculatePaye = (monthlyPay) => {
if (monthlyPay >= 0 && monthlyPay <= 24000){
return monthlyPay * 0.10;
}
else if (monthlyPay >= 24001 && monthlyPay <= 32333){
return monthlyPay * 0.25;
}
else if (monthlyPay >= 32334 && monthlyPay <= 500000){
return monthlyPay * 0.30;
}
else if (monthlyPay >= 500001 && monthlyPay <= 800000){
return monthlyPay * 0.325;
}
else if (monthlyPay > 800000){
return monthlyPay * 0.35;
}
else {return 0; // Default to 0 for invalid input
}
}
//calculate nhif
const calculateNhif = (monthlyPay) => {
return monthlyPay * 0.0275;
}
//calculate nssfRate
const calculateNssf = (monthlyPay) => {
if (monthlyPay > 6000 && monthlyPay <= 18000 ){
return monthlyPay * 0.12
}
else if (monthlyPay >= 18001) {
return monthlyPay * 0.12
}
else {return 0; // default to 0 for invalid input }
};
}
//calculating gross salary//
const grossSalary = salary + benefits;
//calculating paye, nhif and nssf deductions
const payeDeduction = calculatePaye(grossSalary);
const nhifDeduction = calculateNhif(grossSalary);
const nssfDeduction = calculateNssf(grossSalary);
//calculate net salary
const netSalary = grossSalary - (payeDeduction + nhifDeduction + nssfDeduction);
return {
GROSS_Salary: grossSalary,
NET_Salary: netSalary,
PAYE_Deduction: payeDeduction,
NHIF_Deduction: nhifDeduction,
NSSF_Deduction: nssfDeduction
};
}
//example
console.log(calculateNetSalary(100000, 20000));