Tell us what’s happening:
Describe your issue in detail here.
SyntaxError: unknown: Invalid left-hand side in assignment expression. (24:20)
22 | cashToGive[denomination[0]] = 0;
23 | while (cashOnHand[denomination[0]] > 0) {
24 | cashOnHand[[denomination[0]] -= denomination[1];
| ^
25 | }
26 | }
27 | index -= 1;
**Your code so far**
const DENOMINATIONS = [
["PENNY", 1], ["NICKEL", 5], ["DIME", 10],
["QUARTER", 25], ["ONE", 100], ["FIVE", 500],
["TEN", 1000], ["TWENTY", 2000], ["ONE HUNDRED", 10000]
];
function checkCashRegister(price, cash, cid) {
let amountToReturn = Math.round(cash * 100) - Math.round(price * 100);
let cashOnHand = {};
let CashToGive = {};
cid.forEach(function(denomination) {
cashOnHand[denomination[0]] = Math.round(denomination[1] * 100)
})
let index = DENOMINATIONS.lengths - 1;
while (index >= 0) {
let denomination = DENOMINATIONS[index];
if (amountToReturn = denomination[1] > 0) {
cashToGive[denomination[0]] = 0;
while (cashOnHand[denomination[0]] > 0) {
cashOnHand[[denomination[0]] -= denomination[1];
}
}
index -= 1;
}
console.log(amountToReturn, DENOMINATIONS [3] [1]);
}
}
if (amountToReturn === 0) {
let isRegisterEmpty = true;
Object.keys(cashOnHand).forEach(function(moneyType) {
console.log(cashOnHand[moneyType] > 0);
if (cashOnHand[moneyType] > 0) {
isRegisterEmpty = false;
}
});
if (isRegisterEmpty) {
return {
status: "CLOSED"
change: cid
}
} else {
let changeArray = []
Object.keys(cashToGive).map(function(moneyType) {
if(cashToGive).map(function(moneyType) {
changeArray.push([moneyType, cashToGive[moneyType] / 100]);
};
});
return{status: "OPEN", change: changeArray};
}
}
return {status: "INSUFFICIENT_FUNDS", change: []}
}
let res = CheckCashRegister(19.5, 20, [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]);
console.log(res);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36 Edg/92.0.902.84
Challenge: Cash Register
Link to the challenge: