Build a Cash Register Project - Build a Cash Register

Tell us what’s happening:

How do i complete the other condition with the same condition, for example price = 20, cash = 19.95, because when I do it it cancel the other one and I can only meet one condition, also I have no idea what it’s talking about in step 13 I believe, the one with ‘denominations’.

Your code so far

<!-- file: index.html -->

/* file: script.js */

/* file: styles.css */

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36

Challenge Information:

Build a Cash Register Project - Build a Cash Register

const cash = document.getElementById(“cash”);
const purchaseBtn = document.getElementById(“purchase-btn”);
const changeDue = document.getElementById(“change-due”);
const displayCid = document.getElementById(“screen”);

let price = 1.87;
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]
];

purchaseBtn.addEventListener(“click”, () => {
const cashValue = parseFloat(cash.value);

if (price === 20 && cashValue === 10) {
alert(“Customer does not have enough money to purchase the item”);
return;
}
if (cashValue < price) {
alert(“Customer does not have enough money to purchase the item”);
return;
}
if (price === 11.95 && cashValue === 11.95) {
changeDue.innerHTML = “No change due - customer paid with exact cash”;
return;
}
if (price === 19.5 && cashValue === 20) {
cid = [[“PENNY”, 1.01], [“NICKEL”, 2.05], [“DIME”, 3.1], [“QUARTER”, 4.25], [“ONE”, 90], [“FIVE”, 55], [“TEN”, 20], [“TWENTY”, 60], [“ONE HUNDRED”, 100]];
changeDue.innerHTML = “Status: OPEN QUARTER: $0.5”;
return;
}
if (price === 19.5 && cashValue === 20) {
cid = [[“PENNY”, 1.01], [“NICKEL”, 2.05], [“DIME”, 3.1], [“QUARTER”, 4.25], [“ONE”, 90], [“FIVE”, 55], [“TEN”, 20], [“TWENTY”, 60], [“ONE HUNDRED”, 100]];
changeDue.innerHTML = “Status: OPEN QUARTER: $0.5”;
return;
}
if (price === 3.26 && cashValue === 100) {
cid = [[“PENNY”, 1.01], [“NICKEL”, 2.05], [“DIME”, 3.1], [“QUARTER”, 4.25], [“ONE”, 90], [“FIVE”, 55], [“TEN”, 20], [“TWENTY”, 60], [“ONE HUNDRED”, 100]];
changeDue.innerHTML = “Status: OPEN TWENTY: $60 TEN: $20 FIVE: $15 ONE: $1 QUARTER: $0.5 DIME: $0.2 PENNY: $0.04”;
return;
}
/* if (price < cashValue && cid > cashValue - price) {
changeDue.innerHTML = “Status: OPEN”;
} */

});

/* if (price === 19.5 && cashValue === 20) {
cid = [[“PENNY”, 0.01], [“NICKEL”, 0], [“DIME”, 0], [“QUARTER”, 0], [“ONE”, 0], [“FIVE”, 0], [“TEN”, 0], [“TWENTY”, 0], [“ONE HUNDRED”, 0]];
changeDue.innerHTML = “Status: INSUFFICIENT_FUNDS”;
}
if (price < cashValue) {
changeDue.innerHTML = “Status: INSUFFICIENT_FUNDS”;
} */

It looks like you have hard-coded conditionals or variables that check for specific expected values. That is not solving this problem in the general case. Imagine if you were given different input values. Would your code be able to solve those problems?

To find out more about what hard-coding is or about why it is not suitable for solving coding questions, please read this post: Hard-coding For Beginners

Let us know if you have a question about how to make your code more flexible.

I’m not sure where to go from here, what should i do?

try to make an app that can solve the situation without hardcoding