The fatality rate, often referred to as the Case Fatality Rate (CFR) in epidemiology, is a crucial metric used to understand the severity of a disease or condition. It is calculated by dividing the number of deaths caused by a specific disease by the total number of individuals diagnosed with that disease over a particular period.
function calculateFatalityRate() {
var totalCasesInput = document.getElementById("totalCases");
var totalDeathsInput = document.getElementById("totalDeaths");
var resultDiv = document.getElementById("result");
var totalCases = parseFloat(totalCasesInput.value);
var totalDeaths = parseFloat(totalDeathsInput.value);
if (isNaN(totalCases) || isNaN(totalDeaths)) {
resultDiv.innerHTML = "Please enter valid numbers for both cases and deaths.";
return;
}
if (totalCases <= 0) {
resultDiv.innerHTML = "Total number of diagnosed cases must be greater than zero.";
return;
}
if (totalDeaths totalCases) {
resultDiv.innerHTML = "Total number of deaths cannot exceed the total number of diagnosed cases.";
return;
}
var fatalityRate = (totalDeaths / totalCases) * 100;
resultDiv.innerHTML = "The estimated Fatality Rate is: " + fatalityRate.toFixed(2) + "%";
}
#fatality-rate-calculator {
font-family: sans-serif;
padding: 20px;
border: 1px solid #ccc;
border-radius: 8px;
max-width: 400px;
margin: 20px auto;
background-color: #f9f9f9;
}
.input-group {
margin-bottom: 15px;
}
.input-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
.input-group input[type="number"] {
width: calc(100% – 12px);
padding: 8px;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 15px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: #45a049;
}
#result {
margin-top: 20px;
font-size: 18px;
color: #333;
}
#result strong {
color: #d9534f;
}