I completed the Cash Register project but encountered some errors that I couldn’t fix on my own. While the code passed, I had to rely heavily on Google for assistance, leaving me somewhat unsatisfied. It was not so much that I needed to consult Google, but I needed so much help, and I still didn’t fully understand the code. I’m eagerly preparing for the next project, which involves building a Pokemon Search App. It will be challenging, but I’m excited about the learning experience it will provide.
Last night, Tommy prepared some delightful catfish po’boys that I couldn’t resist snacking on. I had to stop myself, though, as the remaining catfish was meant for Lexi, who wasn’t feeling well after spending a day at the local carnival with her friend. She may have gotten too much sun and heat yesterday.
The past weekend was wonderful. We decided to take it easy and stayed home, which I enjoyed. Tommy and I managed to get some exercise over the weekend as we tried to be more active. However, it’s been quite challenging because of the heat indoors. Our swamp cooler still needs to be turned on, but it requires access to the roof. Since we’re renting, we have to wait for the plumber to come and handle that for us.
It has been raining for the majority of the day. I personally enjoy the rain, but I feel for the dogs as it is too muddy for them outside, so they have been stuck in the house all day. Although, Everest is always finding a way to get out of the yard, so she is stuck in the house regardless. We need to fix our fence to prevent her from getting out.
JavaScript notes…
——————————
FreeCodeCamp Cash Register
** start of html **Document ** end of html ** ** start of javascript ** let price = 3.26; let cid = [ ["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100], ]; const displayChangeDue = document.getElementById("change-due"); const cash = document.getElementById("cash"); const purchaseBtn = document.getElementById("purchase-btn"); const priceScreen = document.getElementById("price-screen"); const cashDrawerDisplay = document.getElementById("cash-drawer-display"); const formatResults = (status, change) => { displayChangeDue.innerHTML = `Status: ${status}
`; change.map( (money) => (displayChangeDue.innerHTML += `${money[0]}: $${money[1]}
`), ); return; }; const checkCashRegister = () => { if (Number(cash.value) < price) { alert("Customer does not have enough money to purchase the item"); cash.value = ""; return; } if (Number(cash.value) === price) { displayChangeDue.innerHTML = "No change due - customer paid with exact cash
"; cash.value = ""; return; } let changeDue = Number(cash.value) - price; let reversedCid = [...cid].reverse(); let denominations = [100, 20, 10, 5, 1, 0.25, 0.1, 0.05, 0.01]; let result = { status: "OPEN", change: [] }; let totalCID = parseFloat( cid .map((total) => total[1]) .reduce((prev, curr) => prev + curr) .toFixed(2), ); if (totalCID < changeDue) { return (displayChangeDue.innerHTML = "Status: INSUFFICIENT_FUNDS
"); } if (totalCID === changeDue) { result.status = "CLOSED"; } for (let i = 0; i <= reversedCid.length; i++) { if (changeDue > denominations[i] && changeDue > 0) { let count = 0; let total = reversedCid[i][1]; while (total > 0 && changeDue >= denominations[i]) { total -= denominations[i]; changeDue = parseFloat((changeDue -= denominations[i]).toFixed(2)); count++; } if (count > 0) { result.change.push([reversedCid[i][0], count * denominations[i]]); } } } if (changeDue > 0) { return (displayChangeDue.innerHTML = "Status: INSUFFICIENT_FUNDS
"); } formatResults(result.status, result.change); updateUI(result.change); }; const checkResults = () => { if (!cash.value) { return; } checkCashRegister(); }; const updateUI = (change) => { const currencyNameMap = { PENNY: "Pennies", NICKEL: "Nickels", DIME: "Dimes", QUARTER: "Quarters", ONE: "Ones", FIVE: "Fives", TEN: "Tens", TWENTY: "Twenties", "ONE HUNDRED": "Hundreds", }; if (change) { change.forEach((changeArr) => { const targetArr = cid.find((cidArr) => cidArr[0] === changeArr[0]); targetArr[1] = parseFloat((targetArr[1] - changeArr[1]).toFixed(2)); }); } cash.value = ""; priceScreen.textContent = `Total: $${price}`; cashDrawerDisplay.innerHTML = `Change in drawer:
${cid .map((money) => `${currencyNameMap[money[0]]}: $${money[1]}
`) .join("")} `; }; purchaseBtn.addEventListener("click", checkResults); cash.addEventListener("keydown", (e) => { if (e.key === "Enter") { checkResults(); } }); updateUI(); ** end of javascript **