-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc.js
32 lines (23 loc) · 1.08 KB
/
calc.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
//Calculate Net Salary
//Declare variables
let basicSalary, benefits, payee, NHIFDeductions, NSSFDeductions, grossSalary, netSalary;
//Prompt user to enter basic salary
basicSalary = parseFloat(prompt("Please enter your basic salary:"));
//Prompt user to enter benefits
benefits = parseFloat(prompt("Please enter your benefits:"));
//Calculate payee (i.e. Tax)
payee = Math.floor((basicSalary + benefits) * 0.25);
//Calculate NHIF deductions
NHIFDeductions = Math.floor(basicSalary * 0.03);
//Calculate NSSF deductions
NSSFDeductions = Math.floor(basicSalary * 0.05);
//Calculate gross salary
grossSalary = Math.floor(basicSalary + benefits);
//Calculate net salary
netSalary = grossSalary - payee - NHIFDeductions - NSSFDeductions;
//Display the net salary
console.log(window.alert( `Your P.A.Y.E is ${payee}`));
console.log(window.alert( `Your gross salary is ${grossSalary}`));
console.log(window.alert( `Your NHIF Deduction is ${NHIFDeductions}`));
console.log(window.alert( `Your NSSF Deduction is ${NSSFDeductions}`));
console.log(window.alert(`Your net salary is: Ksh. ${netSalary}`));