Tell us what’s happening:
I have what I believe is a completed backend, however beginning at task #11 and going through the end is not picking up as completed. I believe that’s because instead of 0.5 I’m reporting back 0.50 which in USD is the proper way to do this. You don’t say “i’m giving you back .5 dollars” you say 50 cents (0.50).
Do I need to trim the last 0 or am I missing something else instead that is not complete?
Forgive the lack of CSS. I haven’t gotten to that. I like to get the code working first.
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Point of Sale System</title>
<link rel="stylesheet" href="./styles.css" />
</head>
<body>
<main>
<div id="amt-due"></div>
<input id="cash" ></input>
<button id="purchase-btn">Pay</button>
<div id="change-due"></div>
</main>
<script src="script.js"></script>
</body>
</html>
/* file: script.js */
const items = [];
const cash = document.getElementById("cash").value;
const purchaseBtn = document.getElementById("purchase-btn");
const changeDue = document.getElementById("change-due");
const amtDue = document.getElementById("amt-due");
let price = 19.50;
let cid = [
['PENNY', 1.01, .01],
['NICKEL', 2.05, .05],
['DIME', 3.1, .10],
['QUARTER', 4.25, .25],
['ONE', 90, 1],
['FIVE', 55, 5],
['TEN', 20, 10],
['TWENTY', 60, 20],
['ONE HUNDRED', 100, 100]
];
amtDue.innerHTML = `Amount Due: $${price.toFixed(2)}`;
purchaseBtn.addEventListener("click", () => {
const input = parseFloat(document.getElementById("cash").value);
let change = 0;
let changeString = "Status: OPEN ";
if (!input) {
alert("Please provide an amount");
return;
}
if (input < price) {
alert("Customer does not have enough money to purchase the item")
} else if (input === price) {
changeDue.innerText = "No change due - customer paid with exact cash";
} else {
change = input - price;
cid.sort((a, b) => b[2] - a[2]).forEach(
(denomination) => {
if (denomination[2] <= change) {
let denominationCount = Math.floor(change / denomination[2]);
change -= (denominationCount * denomination[2]);
changeString += `${denomination[0]}: $${(denominationCount * denomination[2]).toFixed(2)} `;
}
}
)
changeDue.innerHTML = changeString ;
}
})
/* file: styles.css */
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Challenge Information:
Build a Cash Register Project - Build a Cash Register