Cash Register CID

Tell us what’s happening:

I’m looking for some advice. I finally got my makeChange function to print to the console as expected. Unfortunately, I needed to use two different arrays (changeArr and legend). I don’t really like this but it works.

At this point, I need to take the cid and start subtracting from that but I’m kind of in a fog as to how to approach it.

Any advice would be apreciated.

Your code so far


function checkCashRegister(price, cash, cid) {
let INSUFFICIENT_FUNDS = {status: "INSUFFICIENT_FUNDS", change: change};
let CLOSED = {status: "CLOSED", change: change};
let OPEN = {status: "OPEN", change: change};
var changeDue = Math.round((cash-price) * 100)/100;
var change = [];
let ledgend = [["PENNY", .01], ["NICKEL", .05], ["DIME", 0.1], ["QUARTER", .25], ["ONE", 1], ["FIVE", 5], ["TEN", 10], ["TWENTY", 20], ["ONE HUNDRED", 100]];
//console.log(changeDue)
function makeChange() {
let changeArr = [.01, .05, .1, .25, 1, 5, 10, 20, 100];
for (let i = ledgend.length-1; changeArr[i] > 0; i--){
   //console.log(ledgend[i])
   if (changeArr[i] <= changeDue){
     if (change.length >= 1 && change[change.length-1][0] === ledgend[i][0]) {
       change[change.length-1][1] = change[change.length-1][1] + changeArr[i]
;
     } else {
       change.push(ledgend[i]);
     }
  changeDue = Math.round((changeDue - changeArr[i]) * 100) / 100;
  //console.log(changeDue, changeArr[i], i, changeArr[i])
  if (changeDue > 0){
    makeChange();
  }
  }
}
}
makeChange()
console.log(change)

function checkDrawer() {
for (let i in cid){
//console.log(cid[i][0], Math.round(cid[i][1]/ledgend[i][1]))
}
}
checkDrawer();

return {status: "", change: ""}
}

checkCashRegister(19.10, 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/87.0.4280.88 Safari/537.36.

Challenge: Cash Register

Link to the challenge:

Consider what exactly you want to achieve in the next step. With what you start and what you want to end up with. Then try to figure out what operations need to happen to do that. If at this point it’s still unclear you can try to think of such operations for a very basic example. Or split actions to more separate smaller steps and tackle them one-by-one.

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