este mi html
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Build a Cash Register Project" />
<title>Build a Cash Register Project</title>
<link rel="stylesheet" href="./styles.css" />
</head>
<body>
<header>
<h1>Cash Register Project</h1>
</header>
<main>
<div id="change-due"></div>
<label for="cash">Enter cash from customer:</label>
<input id="cash" type="number"/>
<button id="purchase-btn" type="button" value>Purchase</button>
<div id="cash-drawer"></div>
</main>
<script src="./script.js"></script>
</body>
</html>
este es mi javascript
const cashInput = document.getElementById("cash");
const changeDueText = document.getElementById("change-due");
const purchaseBtn = document.getElementById("purchase-btn");
//const cashDrawerText = document.getElementById("cash-drawer");
let price = 19.5;
let cid = [
["PENNY", 0.5],
["NICKEL", 0],
["DIME", 0],
["QUARTER", 0],
["ONE", 0],
["FIVE", 0],
["TEN", 0],
["TWENTY", 0],
["ONE HUNDRED", 0]
];
const denominationValues = {
"PENNY": 0.01,
"NICKEL": 0.05,
"DIME": 0.10,
"QUARTER": 0.25,
"ONE": 1,
"FIVE": 5,
"TEN": 10,
"TWENTY": 20,
"ONE HUNDRED": 100
};
const getCID = () => {
return parseFloat(cid.reduce((accumulator, currVal) => accumulator + currVal[1], 0)).toFixed(2);
};
const updateChangeDueText = (customerChange) => {
let text = `Status: ${getCID() > 0 ? "OPEN" : "CLOSED"}`; // Cambiar lógica de cómo se determina el estado
for (const prop in customerChange) {
text += ` ${prop}: $${customerChange[prop].toFixed(2)}`; // Asegúrate de mostrar dos decimales
}
return text;
};
const processPayment = () => {
const isValidString = filterInput(cashInput.value);
if (!isValidString) {
alert("Please enter a valid cash amount.");
return;
}
const cash = parseFloat(cashInput.value);
let changeDue = cash - price;
if (cash < price) {
alert("Customer does not have enough money to purchase the item");
cashInput.value = "";
return;
} else if (cash === price) {
changeDueText.textContent = "No change due - customer paid with exact cash";
cashInput.value = "";
return;
}
const customerChange = {};
for (const denomination of cid) { // Se utiliza cid en lugar de cidReverse
while (changeDue >= denominationValues[denomination[0]] && denomination[1] > 0) {
changeDue = parseFloat((changeDue - denominationValues[denomination[0]]).toFixed(2));
denomination[1] = parseFloat((denomination[1] - denominationValues[denomination[0]]).toFixed(2));
customerChange[denomination[0]] = customerChange[denomination[0]] ?
parseFloat((customerChange[denomination[0]] + denominationValues[denomination[0]]).toFixed(2))
: denominationValues[denomination[0]];
}
}
changeDueText.textContent = changeDue > 0 ? "Status: INSUFFICIENT_FUNDS" : updateChangeDueText(customerChange);
cashInput.value = "";
return;
};
const filterInput = (cashString) => {
return /^(\d+(\.\d{0,2})?)?$/.test(cashString); // Se corrige la expresión regular para aceptar hasta dos decimales
};
purchaseBtn.addEventListener("click", processPayment);
cashInput.addEventListener("keydown", (event) => {
if (event.key === "Enter") {
processPayment();
}
});
porfavor alguien me ayude