Build a Cash Register Project - Build a Cash Register

someone who fixed the unexpected " , " token tell me how please :slightly_smiling_face:

<!-- file: index.html -->
<input type="text" id="cash">
<div id="change-due">
    <button id="purchase-btn"></button>
</div>
<script>
    const 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 cashInput = document.getElementById('cash');
const purchaseBtn = document.getElementById('purchase-btn');
const changeDue = document.getElementById('change-due');

purchaseBtn.addEventListener('click', () => {
    const cash = parseFloat(cashInput.value);
    let change = cash - price;
    let totalCid = cid.reduce((acc, curr) => acc + curr[1], 0);

    if (cash < price) {
        alert("Customer does not have enough money to purchase the item");
    } else if (totalCid < change) {
        changeDue.textContent = "Status: INSUFFICIENT_FUNDS";
    } else if (totalCid === change) {
        changeDue.textContent = "Status: CLOSED";
        for (let i = 0; i < cid.length; i++) {
            cid[i][1] = 0;
        }
        cid[0][1] = change.toFixed(2);
    } else {
        let changeArray = [];
        for (let i = cid.length - 1; i >= 0; i--) {
            let currencyValue = parseFloat(cid[i][1]);
            let currencyUnit = cid[i][0];
            let currencyAmount = 0;

            while (change >= currencyValue && currencyValue > 0) {
                change -= currencyValue;
                currencyAmount += currencyValue;
                change = Math.round(change * 100) / 100;
            }

            if (currencyAmount > 0) {
                changeArray.push(${currencyUnit}: $${currencyAmount.toFixed(2)});
            }
        }

        if (change === 0) {
            changeDue.textContent = "No change due - customer paid with exact cash";
        } else {
            changeDue.textContent = Status: OPEN ${changeArray.join(' ')};
        }
    }
});

</script>
/* file: styles.css */

/* file: script.js */

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0

Challenge Information:

Build a Cash Register Project - Build a Cash Register

You are missing the template literal string around the interpolation. You have the same syntax error in a different place as well.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.