Electricity bill calculator

 Calculation of Electricity bill:-

Calculation of Electricity bill in using html css and javascript code

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="estyle.css">
  <title>Electricity Bill Calculator</title>
  <style>
    body {
  font-family: Arial, sans-serif;
  background-color: #f4f4f4;
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

.calculator-container {
  background-color: #fff;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  text-align: center;
}

label {
  display: block;
  margin-bottom: 10px;
}

input {
  padding: 8px;
  width: 100%;
  margin-bottom: 20px;
  box-sizing: border-box;
}

button {
  background-color: #4caf50;
  color: #fff;
  padding: 10px 20px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

button:hover {
  background-color: #45a049;
}

#result {
  margin-top: 20px;
  font-weight: bold;
}
  </style>
</head>
<body>
  <div class="calculator-container">
    <h1>Electricity Bill Calculator</h1>
    <label for="units">Enter Units Consumed:</label>
    <input type="number" id="units" placeholder="Enter units" />
    <button onclick="calculateBill()">Calculate Bill</button>
    <div id="result"></div>
  </div>

  <script>
    function calculateBill() {
  const units = parseFloat(document.getElementById('units').value);
  const freeUnits = 100;
  const rate = 10; // Change this rate based on your electricity tariff
  let totalBill = 0;
  const resultElement = document.getElementById('result');

  if (!isNaN(units) && units >= 0) {
    if (units <= freeUnits) {
      resultElement.innerHTML = 'Your first 100 units are free!';
    } else {
      totalBill = (units - freeUnits) * rate;
      resultElement.innerHTML = `Your Electricity Bill: $${totalBill.toFixed(2)}`;
    }
  } else {
        resultElement.innerHTML = 'Please enter a valid number of units.';
  }
}
  </script>
</body>
</html>

Comments

Popular posts from this blog

Square value added

HTML tutorials

Date of birth calculator