This is about the Cash Register Javascript DSA project this code is passing the failed test on node but not on FCC can someone tell me what my mistake is?

This code is passing the failed test on node but not on FCC can someone tell me what my mistake is?

const currArray = {

  'PENNY': 1,

  'NICKEL': 5,

  'DIME': 10,

  'QUARTER': 25,

  'DOLLAR': 100,

  "FIVE": 500,

  "TEN": 1000,

  "TWENTY": 2000,

  "ONE HUNDRED": 10000,

};

function checkCashRegister(price, cash, cid) {

  let changeAmount = cash * 100 - price * 100;

  const changeVarUsedLater = changeAmount;

  let moneyInDrawer=0;

  let message = { status: null, change: [] };

  let nonZeroCid = [];

  for (let e of cid){

    if (e[1]!==0){

      nonZeroCid.push(e);

    }

  }

  nonZeroCid.reverse();

  // console.log(nonZeroCid);

  for (let element of nonZeroCid){

    let currency = element[0];

    // console.log(currency);

    let currencyAvailable = element[1]*100;

    moneyInDrawer+=currencyAvailable;

    let usedCurrency = 0;

    while (changeAmount>=currArray[currency] && currencyAvailable>0){

      usedCurrency+=currArray[currency];

      changeAmount-=currArray[currency];

      currencyAvailable-=currArray[currency];

    }

    if (usedCurrency !==0){

      message.change.push([currency,usedCurrency/100]);

      // console.log(message.change);

    }

  }

  if (changeAmount>0){

    message.status = 'INSUFFICIENT FUNDS';

    message.change=[];

  }else if(changeAmount===0 && changeVarUsedLater===moneyInDrawer){

    message.status='CLOSED';

    message.change=cid; // For some reason FCC wants me to resturn the CID instead of the non null change array

  }else{

    message.status='OPEN';

  }

  return message;

}

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Could you describe your problem in more detail? By just providing the code, you are asking us to play hide-and-go-seek with your bug. Thanks.

Edit: (let e of cid) I do not believe the order is specified in this loop.

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