Cash Register to review and provide guidance to a solution

Tell us what’s happening:
I am receiving a type err on the .length and cannot seem to figure out the error message. I looked at this code for three days and cannot find the mistake. can a get some hints as to what is wrong with the code.

Your code so far


const register_Status = { Closed : "CLOSED",Insuf : "INSUFFICIENT_FUNDS",Open: "OPEN"
};
var denom  = [
{ name: "ONE HUNDRED", val: 100.0 },
{ name: "TWENTY", val: 20.0 },
{ name: "TEN", val: 10.0 },
{ name: "FIVE", val: 5.0 },
{ name: "ONE", val: 1.0 },
{ name: "QUARTER", val: 0.25 },
{ name: "DIME", val: 0.1 },
{ name: "NICKEL", val: 0.05 },
{ name: "PENNY", val: 0.01 }
];
//const change = [];
function checkCashRegister(price, cash, cid) {
const changeNeeded= parseFloat(cash - price).toFixed(2);
let cashregister = { status : [], change: cid };
const changeAvail = getTotalFromRegister(cid);
let registerStatus = getRegisterStatus(changeNeeded, changeAvail);
console.log(cid.length);

if(registerStatus === register_Status.Insuf) {
cashregister.change = [];
  return cashregister;
}
cashregister.change = getChangeInDrawer(changeNeeded, cid);

if(changeNeeded > getChangeInDrawer(cashregister.change)) {

  cashregister.status = register_Status.Insuf;
  cashregister.change = [];
}

if(cashregister.status === register_Status.closed) {
  cashregister.change = [...cid];
  }
console.log(cashregister);
return cashregister;
}

//calculating the change remaining and create the object

function getChangeInDrawer(changeNeeded, changeInDrawer){
const change = [];
//console.log(typeof(changeInDrawer));
for (let i = changeInDrawer.length - 1; i>=0 ; i-- ){
  
    const coinName =changeInDrawer[i][0];
    const coinTotal = changeInDrawer[i][1];
    const coinValue = denom.coinName;
     let coinAmt = (coinTotal/ coinValue).toFixed(2);
    let coinsToReturn = 0;
//console.log(changeInDrawer.length);
  while(changeNeeded >= coinValue && coinAmt > 0){
    changeNeeded -= coinValue;
    changeNeeded = changeNeeded.toFixed(2);
    coinAmt --;
    coinsToReturn ++;
  }
  if(coinsToReturn > 0) {
    change.push([coinName, coinsToReturn * coinsValue]);
   }
 //console.log("change =" + changeNeeded);
  }

return change;
}

//total up the amount in the register
function getTotalFromRegister(changeInDrawer) {
let total = 0;
for(let change in changeInDrawer) {
let changeValue = change[1];
total += changeValue;
}
return total.toFixed(2);
}

function getRegisterStatus(changeNeeded, changeAvail)
{
console.log(changeNeeded, changeAvail) 
if(changeNeeded > changeAvail) {
 return register_Status.Insuf;
}  
if(changeNeeded < changeAvail) {
 return register_Status.Open;
}
return register_Status.Closed; 
};




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

Your browser information:

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

Challenge: Cash Register

Link to the challenge:

what’s the error you get?

TypeError: Cannot read property ‘length’ of undefined

there is also the line indicated

when you call the function, getChangeInDrawer, how many arguments are you putting in? I see only one, so changeInDrawer is undefined

This should be the change that is return to customer and the second part of the object that is returned. return the status and the change in drawer.

I have rethink my logic.

I had several problems with the code however you did get me in the correct direction. I was calling the wrong function I should called my totalindrawer function instead. So I have completed mistakes and passed the certification.