Electricity Rate Calculator
This calculator helps you understand the cost of your electricity consumption. By inputting your electricity usage and the rate you are charged, you can estimate your total electricity bill. This can be useful for identifying high-usage appliances or understanding the impact of changing electricity tariffs.
.electricity-calculator-container {
font-family: sans-serif;
max-width: 500px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
background-color: #f9f9f9;
}
.calculator-inputs {
margin-bottom: 20px;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
.form-group input[type="number"] {
width: calc(100% – 20px);
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
button {
padding: 10px 20px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: #45a049;
}
#result {
margin-top: 20px;
font-weight: bold;
color: #333;
border-top: 1px solid #eee;
padding-top: 15px;
}
function calculateElectricityCost() {
var kwhUsed = parseFloat(document.getElementById("kwhUsed").value);
var ratePerKwh = parseFloat(document.getElementById("ratePerKwh").value);
var resultElement = document.getElementById("result");
if (isNaN(kwhUsed) || isNaN(ratePerKwh) || kwhUsed < 0 || ratePerKwh < 0) {
resultElement.innerHTML = "Please enter valid positive numbers for kWh Used and Rate per kWh.";
return;
}
var totalCost = kwhUsed * ratePerKwh;
resultElement.innerHTML = "Estimated Electricity Cost: $" + totalCost.toFixed(2);
}