[SOLVED] Exact Change: having trouble with the grader!

Hi everyone,

I’m having a problem with the challenge grader.

None of the test cases when my algorithm is supposed to return a string are graded correctly.
I’m referring to the cases when the cash-in-drawer is less than or equal to the change due. We’re supposed to return “Insufficient Funds”, or “Closed”, which is what is returned (and printed on the output console) when I run my code. However, the grader still says I’m doing something wrong. :face_with_raised_eyebrow:

Here’s a snippet of the code:

var change = cash - price; 
if (change > cashInDrawer) { // cashInDrawer is calculated before this snippet
  return 'Insufficient Funds';
}
if (change === cashInDrawer) {
  return 'Closed';
}

Attached is a screenshot of the grader results. As you can see, all the other test cases are working correctly.

Challenge_Grader

What could be wrong? :confused:

Thanks in advance for your help. :grinning:

Alright! I figured out what was wrong with my code! :grinning:

I am using a global variable cashDrawer (an array) to hold all the available currency (and amount).
However, I had forgotten to reset cashDrawer in between calls to checkRegister !!! :flushed:

It’s working perfect now… I can finally move onto the next! :smiley: