Professional Documents
Culture Documents
Milk
Milk
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Milk Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
}
table {
border-collapse: collapse;
margin-bottom: 20px;
}
th, td {
border: 1px solid black;
padding: 8px;
text-align: center;
}
#totalMilk, #totalIncrement, #totalDecrement, #resultX, #finalMilk, #amount
{
font-weight: bold;
}
#resultBox {
margin-top: 20px;
border: 1px solid black;
padding: 10px;
width: 200px;
}
</style>
<script>
function addRow() {
var table = document.getElementById("calculatorTable");
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
function deleteRow() {
var table = document.getElementById("calculatorTable");
var rowCount = table.rows.length;
if (rowCount > 2) {
table.deleteRow(rowCount - 1);
}
}
function calculate() {
var table = document.getElementById("calculatorTable");
var rowCount = table.rows.length;
var totalMilk = 0;
var totalIncrement = 0;
var totalDecrement = 0;
var totalX = 0;
var finalMilk = 0;
var amount = 0;
// Calculate total X
totalX = ((totalDecrement - totalIncrement) * 1.5) / 100;
// Calculate amount
amount = finalMilk * rate;
// Display results
document.getElementById('totalMilk').innerHTML = totalMilk.toFixed(2);
document.getElementById('totalDecrement').innerHTML =
totalDecrement.toFixed(2);
document.getElementById('totalIncrement').innerHTML =
totalIncrement.toFixed(2);
document.getElementById('resultX').innerHTML = totalX.toFixed(2);
document.getElementById('finalMilk').innerHTML = finalMilk.toFixed(2);
document.getElementById('amount').innerHTML = amount.toFixed(2);
}
</script>
</head>
<body>
<h1>Calculator</h1>
<table id="calculatorTable">
<tr>
<th>Numbering</th>
<th>Milk</th>
<th>Sample</th>
<th>Decrement</th>
<th>Increment</th>
</tr>
<!-- Initial row -->
<tr>
<td>1</td>
<td><input type="number" id="milk1"></td>
<td><input type="number" id="sample1"></td>
<td><input type="text" id="decrement1"></td>
<td><input type="text" id="increment1"></td>
</tr>
</table>
<label for="rate">Rate:</label>
<input type="number" id="rate" placeholder="Enter rate">
<button onclick="addRow()">Add Row</button>
<button onclick="deleteRow()">Delete Row</button>
<button onclick="calculate()">Calculate</button>
<div id="resultBox">
<p>Total Milk (without roundoff): <span id="totalMilk">0</span></p>
<p>Total Decrement: <span id="totalDecrement">0</span></p>
<p>Total Increment: <span id="totalIncrement">0</span></p>
<p>Result X: <span id="resultX">0</span></p>
<p>Final Milk: <span id="finalMilk">0</span></p>
<p>Amount: <span id="amount">0</span></p>
</div>
</body>
</html>