-
Notifications
You must be signed in to change notification settings - Fork 0
/
Net Salary Calculator.js
102 lines (94 loc) · 2.36 KB
/
Net Salary Calculator.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const readline = require("readline");
let rl = readline.createInterface(process.stdin, process.stdout);
function getTaxRate(salary) {
if(salary <= 24000){
return 10;
}
if (salary > 24000 && salary <= 32333.33){
return 25;
}
if (salary > 32333.33 && salary <= 499999.99){
return 30;
}
if (salary > 500000.00 && salary <= 799999.99){
return 32.5;
}
return 35;
}
getTaxRate();
function salaryAfterPaye(salary){
const rate = getTaxRate(salary) / 100;
const taxable = salary * rate;
const income = salary - taxable;
const net = income + 2640;
return net;
}
function nhifDeductible(income){
if (income <= 5999) {
return 150;
}
if (income >= 6000 && income <= 7999) {
return 300;
}
if (income >= 8000 && income <= 11999) {
return 400;
}
if (income >= 12000 && income <= 14999) {
return 500;
}
if (income >= 15000 && income <= 19999) {
return 600;
}
if (income >= 20000 && income <= 24999) {
return 750;
}
if (income >= 25000 && income <= 29999) {
return 850;
}
if (income >= 30000 && income <= 34999) {
return 900;
}
if (income >= 35000 && income <= 39999) {
return 950;
}
if (income >= 40000 && income <= 44999) {
return 1000;
}
if (income >= 45000 && income <= 49999) {
return 1100;
}
if (income >= 50000 && income <= 59999) {
return 1200;
}
if (income >= 60000 && income <= 69999) {
return 1300;
}
if (income >= 70000 && income <= 79999) {
return 1400;
}
if (income >= 80000 && income <= 89999) {
return 1500;
}
if (income >= 90000 && income <= 99999) {
return 1600;
}
return 1700;
}
function NetSalary(salary){
const afterPaye = salaryAfterPaye(salary);
const nhif = nhifDeductible(salary);
return afterPaye - nhif;
}
function main() {
rl.question("Enter your gross salary\n", (salary) => {
let s = parseInt(salary);
if (isNaN(s)) {
console.log("Please enter a valid numerical salary.\n");
main();
return;
}
console.log("If your gross salary is ",salary, " Ksh,", "your net salary is ", NetSalary(salary), "Ksh. I've paid my taxes!");
rl.close();
});
}
main();