Result:
Enter the values above to calculate the crude death rate.
.calculator-container {
font-family: 'Arial', sans-serif;
max-width: 600px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
background-color: #f9f9f9;
}
.calculator-title {
text-align: center;
color: #333;
margin-bottom: 15px;
}
.calculator-description {
color: #555;
line-height: 1.6;
margin-bottom: 25px;
text-align: justify;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 8px;
font-weight: bold;
color: #444;
}
.form-group input[type="number"] {
width: calc(100% – 12px);
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 1rem;
}
.calculate-button {
display: block;
width: 100%;
padding: 12px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
font-size: 1.1rem;
cursor: pointer;
transition: background-color 0.3s ease;
}
.calculate-button:hover {
background-color: #0056b3;
}
.calculator-result {
margin-top: 30px;
padding: 20px;
border: 1px solid #eee;
border-radius: 8px;
background-color: #fff;
}
.result-title {
color: #333;
margin-bottom: 15px;
text-align: center;
}
#result {
text-align: center;
font-size: 1.2rem;
color: #007bff;
font-weight: bold;
}
#result p {
margin: 0;
}
function calculateCrudeDeathRate() {
var numberOfDeathsInput = document.getElementById("numberOfDeaths");
var totalPopulationInput = document.getElementById("totalPopulation");
var resultDiv = document.getElementById("result");
var numberOfDeaths = parseFloat(numberOfDeathsInput.value);
var totalPopulation = parseFloat(totalPopulationInput.value);
if (isNaN(numberOfDeaths) || isNaN(totalPopulation)) {
resultDiv.innerHTML = "Please enter valid numbers for both fields.";
return;
}
if (numberOfDeaths < 0 || totalPopulation <= 0) {
resultDiv.innerHTML = "Number of deaths cannot be negative, and population must be greater than zero.";
return;
}
var crudeDeathRate = (numberOfDeaths / totalPopulation) * 1000;
resultDiv.innerHTML = "" + crudeDeathRate.toFixed(2) + " deaths per 1,000 population";
}