Cash Register test will not pass me

My Input:

console.log(checkCashRegister(19.5, 20, [["PENNY",0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]));

My Output: {
  status: 'CLOSED',
  change: [
    [ 'PENNY', 0.5 ],
    [ 'NICKEL', 0 ],
    [ 'DIME', 0 ],
    [ 'QUARTER', 0 ],
    [ 'ONE', 0 ],
    [ 'FIVE', 0 ],
    [ 'TEN', 0 ],
    [ 'TWENTY', 0 ],
    [ 'ONE HUNDRED', 0 ]
  ]
}
Test Error: 
checkCashRegister(19.5, 20, [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]])

shold return

{status: "CLOSED", change: [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]}

Describe your issue in detail here.
As you can see, my output is the same as the test error’s output yet it will not pass my code. This is the ONLY one it will not pass. Any thoughts? Please? Thank You.

**Your code so far**

function checkCashRegister(price, cash, cid) {
var changeDue = ((cash * 100) - (price * 100));
const denomArr = [1, 5, 10, 25, 100, 500, 1000, 2000, 10000];
var result = new Object();
var changeArr = [];
var holdArr = [];
var regCheck = 0;
var denomCheck = 0;
var cashDeduct = 0;
var chngDeduct = 0;
for (let x = cid.length - 1; x >= 0; x--) {
    if (denomArr[x] < changeDue) {
        regCheck += (cid[x][1] * 100);
    }
}
if (regCheck < changeDue) {
    result.status = "INSUFFICIENT_FUNDS";
    result.change = [];
} else {
    if (regCheck == changeDue) {
        result.status = "CLOSED";
    } else {
        result.status = "OPEN";
    }
    for (let y = cid.length - 1; y >= 0; y--) {
        holdArr = [];
        if (cid[y][1] > 0) {
            regCheck = (cid[y][1] * 100);
            denomCheck = denomArr[y];
            if (denomCheck < changeDue) {
                if (regCheck <= changeDue) {
                    changeDue -= regCheck;
                    holdArr.push(cid[y][0]);
                    holdArr.push(cid[y][1]);
                    changeArr.push(holdArr);
                } else {
                    cashDeduct = Math.floor(changeDue % denomCheck);
                    chngDeduct = changeDue - cashDeduct;
                    changeDue -= chngDeduct;
                    holdArr.push(cid[y][0]);
                    holdArr.push(chngDeduct / 100);
                    changeArr.push(holdArr);
                }
            }
        }
    }
}
result.change = changeArr;
if (result.status == "CLOSED") {
    for (x = 1; x < cid.length; x++) {
        holdArr = [];
        holdArr.push(cid[x][0]);
        holdArr.push(cid[x][1]);
        changeArr.push(holdArr);
    }
}
return result;
}

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/99.0.4844.74 Safari/537.36 Edg/99.0.1150.46

Challenge: Cash Register

Link to the challenge:

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 (’).

try to paste the test you are not passing in your editor and debug it a bit, it’s pretty easy to solve, so I am not going t give you much hints other than try to debug

And just to be clear, when I run this in the FCC window with the failing test data:

checkCashRegister(19.5, 20, [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]])

It does not give the correct result. The test data you have above is a little different.This is not a working solution. As ilena alludes, it is a pretty easy fix, but just to be clear, this answer as is should not pass.

OK. I tried pasting the failing string into my program. I then copied and pasted my results and the test results into word to compare the results lines. The only differences I found were some spacing issues and single quotes instead of double quotes. What am I missing?

Did you try copying the failing test in and testing in the fCC editor? I suspect you have an insufficiently strict test environment.

Side note: don’t use var - let and const should be used

While I am old hat at programming languages, I am new to the modern editing environments including the Visual Studio Code I currently have. I am unfamiliar with the fCC editor you mentioned. Will this reveal to me the differences I am looking for?

You know the thing you pasted your code into to run the tests?

Try adding the failing test case at the bottom with:

Never mind, I am still new also to the shortcut statements. fCC = freeCodeCamp editor. Sorry.

Thanks for all your help. I had a DOOOH moment when I found it. I really appreciate your help.

1 Like