.calculator-wrapper {
font-family: sans-serif;
max-width: 600px;
margin: 20px auto;
padding: 20px;
border: 1px solid #e0e0e0;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.calculator-form h2 {
text-align: center;
margin-bottom: 15px;
color: #333;
}
.calculator-form p {
text-align: center;
color: #555;
margin-bottom: 25px;
font-size: 0.95em;
}
.form-field {
margin-bottom: 15px;
display: flex;
flex-direction: column;
}
.form-field label {
margin-bottom: 5px;
font-weight: bold;
color: #444;
}
.form-field input {
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 1em;
box-sizing: border-box; /* Important for consistent padding */
}
.form-field input:focus {
outline: none;
border-color: #007bff;
box-shadow: 0 0 0 2px rgba(0,123,255,0.25);
}
.calculator-form button {
width: 100%;
padding: 12px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
font-size: 1.1em;
cursor: pointer;
transition: background-color 0.2s ease;
}
.calculator-form button:hover {
background-color: #0056b3;
}
.calculator-result {
margin-top: 30px;
padding: 15px;
background-color: #f8f9fa;
border: 1px solid #e0e0e0;
border-radius: 4px;
text-align: center;
}
.calculator-result h3 {
margin-bottom: 10px;
color: #333;
}
#hourlyRateResult {
font-size: 1.8em;
font-weight: bold;
color: #28a745; /* Green for positive result */
}
function calculateHourlyRate() {
var totalHoursInput = document.getElementById("totalHours");
var totalEarningsInput = document.getElementById("totalEarnings");
var hourlyRateResultDiv = document.getElementById("hourlyRateResult");
var totalHours = parseFloat(totalHoursInput.value);
var totalEarnings = parseFloat(totalEarningsInput.value);
if (isNaN(totalHours) || isNaN(totalEarnings)) {
hourlyRateResultDiv.textContent = "Please enter valid numbers for both fields.";
hourlyRateResultDiv.style.color = "#dc3545"; /* Red for error */
return;
}
if (totalHours <= 0) {
hourlyRateResultDiv.textContent = "Total hours worked must be greater than zero.";
hourlyRateResultDiv.style.color = "#dc3545"; /* Red for error */
return;
}
if (totalEarnings < 0) {
hourlyRateResultDiv.textContent = "Total earnings cannot be negative.";
hourlyRateResultDiv.style.color = "#dc3545"; /* Red for error */
return;
}
var hourlyRate = totalEarnings / totalHours;
hourlyRateResultDiv.textContent = "$" + hourlyRate.toFixed(2);
hourlyRateResultDiv.style.color = "#28a745"; /* Green for success */
}