.calculator-wrapper {
font-family: Arial, sans-serif;
max-width: 600px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
background-color: #fff;
}
.calculator-title {
text-align: center;
color: #333;
margin-bottom: 15px;
}
.calculator-description {
font-size: 0.9em;
color: #555;
line-height: 1.5;
margin-bottom: 20px;
text-align: justify;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #444;
}
.form-group input[type="number"] {
width: calc(100% – 22px);
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
.calculator-wrapper button {
display: block;
width: 100%;
padding: 12px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
font-size: 1em;
cursor: pointer;
transition: background-color 0.3s ease;
}
.calculator-wrapper button:hover {
background-color: #0056b3;
}
.calculator-result {
margin-top: 25px;
padding: 15px;
background-color: #f8f9fa;
border: 1px solid #e0e0e0;
border-radius: 4px;
text-align: center;
}
.result-title {
margin-top: 0;
margin-bottom: 10px;
color: #333;
font-size: 1.1em;
}
#result {
font-size: 2em;
font-weight: bold;
color: #28a745;
margin-bottom: 5px;
}
.result-unit {
font-size: 0.9em;
color: #6c757d;
margin-bottom: 0;
}
function calculateAttritionRate() {
var startEmployees = parseFloat(document.getElementById("employeesAtStart").value);
var endEmployees = parseFloat(document.getElementById("employeesAtEnd").value);
var departedEmployees = parseFloat(document.getElementById("employeesDeparted").value);
var resultElement = document.getElementById("result");
if (isNaN(startEmployees) || isNaN(endEmployees) || isNaN(departedEmployees)) {
resultElement.innerHTML = "Invalid input";
resultElement.style.color = "#dc3545";
return;
}
// A common formula for attrition rate is: (Number of Employees Departed / Average Number of Employees) * 100
// Average number of employees = (Employees at Start + Employees at End) / 2
var averageEmployees = (startEmployees + endEmployees) / 2;
if (averageEmployees === 0) {
resultElement.innerHTML = "N/A";
resultElement.style.color = "#6c757d";
return;
}
var attritionRate = (departedEmployees / averageEmployees) * 100;
if (isNaN(attritionRate) || !isFinite(attritionRate)) {
resultElement.innerHTML = "Error";
resultElement.style.color = "#dc3545";
} else {
resultElement.innerHTML = attritionRate.toFixed(2);
resultElement.style.color = "#28a745";
}
}