Cash Register - off by one penny

  1. I’d suggest wrapping your toFixed calls in Number() so you are not using strings.

  2. The algorithm is working it is just the way you use the makeChange function. Try calling and capturing the return one time and use it for the if statement and return value.

if (changeDue < drawerBalance) {
  let changeBack = makeChange(cid, changeDue);
  if (changeBack == false) {
    return { status: 'INSUFFICIENT_FUNDS', change: [] };
  } else {
    return { status: 'OPEN', change: changeBack };
  }
}
1 Like