# Need assistance with cash register project

Tell us what’s happening:
I am having trouble being able to get the right amount of change given the cash in drawer. It seems that my code is able to provide the correct amount of change, but I can’t seem to figure out how to use the CID to allow the function to move on from one unit of money to the next when it is out of stock, or does not have sufficient funds.

``````

function checkCashRegister(price, cash, cid) {
let change = cash-price;
let unit = [['ONE HUNDRED', 0], ['TWENTY', 0] , ['TEN', 0], ['FIVE', 0], ['DOLLAR', 0], ['QUARTER', 0], ['DIME', 0], ['NICKEL', 0], ['PENNY', 0]]
let value = [100, 20, 10, 5, 1, 0.25, 0.10, 0.05, 0.01]
let cidValues = []
let numbers = []
let sum = 0
let open = []
let closed = []
for (var i = 0; i < cid.length; i++){
sum = sum + cid[i][1]
} // finding sum of cash in drawer

for (var k = cid.length - 1; k >= 0; k--){
cidValues.push(cid[k][1]) // listing the amount of each unit
numbers = cidValues[k]/value[k]
}

for(let j = 0; j < value.length; j++){ // LOOPING THRU TO GET TOTALS
let total = 0
let x = 0
while(change >= value[j]){
change = change - value[j]
total = total + value[j]
x++
if (x === cidValues[j]){
break
}
} if(total[j] > cidValues[j]){
return {status:"INSUFFICIENT_FUNDS", change: []}
}
unit[j][1] = total
} console.log(unit)

if (sum < change){
return {status:"INSUFFICIENT_FUNDS", change: []}
} else if (sum === change){
return {status:"CLOSED", change: unit}
} else if (sum > change){
return {status:"OPEN", change:unit}
}
}

checkCashRegister(19.5, 25, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);

``````

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

Challenge: Cash Register

It seems like your for loop to generate numbers isn’t doing anything:

``````for (var k = cid.length - 1; k >= 0; k--){
cidValues.push(cid[k][1]) // listing the amount of each unit
numbers = cidValues[k]/value[k]  // this should be push if you are trying to generate an array
}
console.log(numbers)

``````

Also I don’t see you using numbers later in the code. Maybe look into how you are keeping track of the number of change items and how much are used. Personally I think I used an object for the change but you can use arrays so long as you make sure they correlate / cross-refer how you want.

While updating that, consider your while loop to calculate the change. Remember that it has to be built for a situation where the change in the drawer’s value is greater than the change to be given, but still the funds are insufficient because the denominations in the drawer aren’t right. (E.g., \$4 owed but only one \$5 bill in drawer.)

A post was split to a new topic: Cash Register -help