-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsalary.html
63 lines (52 loc) · 1.94 KB
/
salary.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
</head>
<body>
<div>
<h1>Net Salary Calculator</h1>
<form id="salary-form">
<label for="basic-salary">Basic Salary:</label>
<input type="number" id="basic-salary" name="basic-salary"><br>
<label for="benefits">Benefits:</label>
<input type="number" id="benefits" name="benefits"><br>
<button type="button" id="calculate-button">Calculate</button>
</form>
<div id="result"></div>
</div>
<script type="text/javascript">
// NET SALARY CALCULATOR
//calculating the net salary
function calculateNetSalary() {
// Get the input values
let basicSalary = parseFloat(document.getElementById("basic-salary").value);
let benefits = parseFloat(document.getElementById("benefits").value);
//Calculating the payee
let payee = Math.floor((basicSalary + benefits) * 0.25);
//Calculating the NHIF deductions
let NHIFDeductions = Math.floor(basicSalary * 0.02);
//Calculating the NSSF deductions
let NSSFDeductions = Math.floor(basicSalary * 0.12);
//Calculating the gross salary
let grossSalary = Math.floor(basicSalary + benefits);
//Calculating the net salary
let netSalary = grossSalary - payee - NHIFDeductions - NSSFDeductions;
//Display the net salary
let resultElement = document.getElementById("result");
resultElement.innerHTML = `
<p>Your P.A.Y.E is ${payee}</p>
<p>Your gross salary is ${grossSalary}</p>
<p>Your NHIF Deduction is ${NHIFDeductions}</p>
<p>Your NSSF Deduction is ${NSSFDeductions}</p>
<p>Your net salary is: Ksh. ${netSalary}</p>
`;
}
// an event listener for the calculate button
let calculateButton = document.getElementById("calculate-button");
calculateButton.addEventListener("click", calculateNetSalary);
</script>
</body>
</html>