-
Notifications
You must be signed in to change notification settings - Fork 0
/
Electricity Bill Calculator.html
47 lines (36 loc) · 1.29 KB
/
Electricity Bill Calculator.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<html>
<body>
<h1>Electricity Bill Calculator</h1>
<p>Enter your name:</p>
<input type="text" id="name"><br>
<p>Enter the month and year:</p>
<input type="text" id="month" placeholder="Month">
<input type="number" id="year" placeholder="Year"><br>
<p>Enter the number of units consumed:</p>
<input type="number" id="units"><br>
<p>Enter the cost per unit:</p>
<input type="number" id="cost"><br>
<button onclick="calculateBill()">Calculate</button>
<p id="result"></p>
<script>
function calculateBill() {
// Get the values from the input fields
var name = document.getElementById("name").value;
var month = document.getElementById("month").value;
var year = document.getElementById("year").value;
var units = document.getElementById("units").value;
var cost = document.getElementById("cost").value;
// Calculate the total cost
var totalCost = units * cost;
// Print the electricity bill
var bill = "Electricity Bill for " + name + "<br>" +
"Month: " + month + "<br>" +
"Year: " + year + "<br>" +
"Number of Units: " + units + "<br>" +
"Cost per Unit: " + cost + "<br>" +
"Total Cost: " + totalCost;
document.getElementById("result").innerHTML = bill;
}
</script>
</body>
</html>