This calculator helps you understand how crime rates are typically calculated. Crime rates are usually expressed as the number of reported crimes per a specific number of people, most commonly per 100,000 residents. This allows for standardized comparison between different geographic areas and over time, regardless of population size.
function calculateCrimeRate() {
var reportedCrimes = parseFloat(document.getElementById("reportedCrimes").value);
var population = parseFloat(document.getElementById("population").value);
var perUnit = parseFloat(document.getElementById("perUnit").value);
var resultDiv = document.getElementById("result");
if (isNaN(reportedCrimes) || isNaN(population) || isNaN(perUnit)) {
resultDiv.innerHTML = "Please enter valid numbers for all fields.";
return;
}
if (population <= 0) {
resultDiv.innerHTML = "Population must be a positive number.";
return;
}
if (perUnit <= 0) {
resultDiv.innerHTML = "The 'Per Unit' value must be a positive number.";
return;
}
// The formula for crime rate is: (Number of Reported Crimes / Total Population) * Per Unit
var crimeRate = (reportedCrimes / population) * perUnit;
resultDiv.innerHTML = "The calculated crime rate is: " + crimeRate.toFixed(2) + " per " + perUnit.toLocaleString() + " people.";
}
.calculator-container {
font-family: sans-serif;
border: 1px solid #ddd;
padding: 20px;
border-radius: 8px;
max-width: 500px;
margin: 20px auto;
background-color: #f9f9f9;
}
.calculator-container h2 {
text-align: center;
margin-bottom: 20px;
color: #333;
}
.input-section {
margin-bottom: 15px;
}
.input-section label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #555;
}
.input-section input[type="number"] {
width: calc(100% – 12px);
padding: 8px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
.calculator-container button {
display: block;
width: 100%;
padding: 10px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s ease;
}
.calculator-container button:hover {
background-color: #0056b3;
}
#result {
margin-top: 20px;
padding: 10px;
background-color: #e9ecef;
border: 1px solid #ced4da;
border-radius: 4px;
text-align: center;
font-size: 1.1em;
color: #333;
}