JavaScript Algorithms and Data Structures Projects - Cash Register

Tell us what’s happening:

Describe your issue in detail here.

Your code so far

function checkCashRegister(price, cash, cid) {
  let change = cash * 100 - price * 100;
  //console.log(change)
  let cidTotal = 0;
  for(let elem of cid) {
  cidTotal += elem[1] * 100;
  //console.log(cidTotal)
}
if (change > cidTotal) {
return {status: "INSUFFICIENT_FUNDS", change: []};
} else if (change === cidTotal) {
  return {status: "CLOSED", change: cid};
}else {
  let result = [];
  // console.log(cid)
  cid = cid.reverse();
  // console.log(cid)
  let currencyUnit = {
  "PENNY": 1,
  "NICKEL": 5,
  "DIME": 10,
  "QUARTER": 25,
  "ONE": 100,
  "FIVE ": 500,
  "TEN": 1000,
  "TWENTY": 2000,
  "ONE HUNDRED": 10000
  }
  for (let elem of cid) {
  let moneyHolder = [elem[0], 0];
 // console.log(moneyHolder);
 elem[1] = elem[1] * 100;
 while (change >= currencyUnit[elem[0]] && elem[1] > 0) {
// console.log(currencyUnit[elem[0]]);
// console.log(elem[1]);
change -= currencyUnit[elem[0]];
// console.log(change);
   elem[1] -= currencyUnit[elem[0]];
   // console.log(elem[1]);
      // console.log(moneyHolder);
   moneyHolder[1] += currencyUnit[elem[0]] / 100;
   // console.log(moneyHolder);
 }
 if(moneyHolder[1] > 0) {
result.push(moneyHolder);
//console.log(result);
 }
  }
  if(change > 0) {
return {status: "INSUFFICIENT_FUNDS", change: []}
  }
  return { status: "OPEN", change: result }
}
}

console.log(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/120.0.0.0 Safari/537.36 Edg/120.0.0.0

Challenge Information:

JavaScript Algorithms and Data Structures Projects - Cash Register

Hello @smuhammad !

What is the issue you are having?

checkCashRegister(3.26, 100, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]) should return {status: "OPEN", change: [["TWENTY", 60], ["TEN", 20], ["FIVE", 15], ["ONE", 1], ["QUARTER", 0.5], ["DIME", 0.2], ["PENNY", 0.04]]} .

the Said That I did Not Pass I most Finished This And I did My Best I can’t Solve It That Is Why i AM Looking For Help

Ok, so why do you think it isn’t passing? Are any of the tests passing?

Yes All Of The Test Are Passing But It Is The Only One That Its Not Passing

Can You Pls Help ME And Send Your Solution

Your code is returning:
{ status: ‘OPEN’,
change:
[ [ ‘TWENTY’, 60 ],
[ ‘TEN’, 20 ],
[ ‘ONE’, 16 ],
[ ‘QUARTER’, 0.5 ],
[ ‘DIME’, 0.2 ],
[ ‘PENNY’, 0.04 ] ] }

The desired output is:
{status: "OPEN", change: [["TWENTY", 60], ["TEN", 20], ["FIVE", 15], ["ONE", 1], ["QUARTER", 0.5], ["DIME", 0.2], ["PENNY", 0.04]]}

Indicating, that something is wrong in the code where you are making change.

SO WHere Would I Make The Change

As this is a certification project that you have written, I was hoping that you might be able to suggest something yourself. Giving you the solution is not within the spirit of this community and it would scarcely benefit man nor beast.

You are almost there and you should persist in acheiving the correct result. Suggest something constructive and I will be more than happy to help.

Try explaining the logic behind the code making change.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.