Cash Register Test Help

Tell us what’s happening:
I put this code into the test and it fails, showing what my output should be. The problem I am having with this is I test their input using Visual Studio Code and the program as it is produces the results the test says it should. I don’t understand why this works fine in Visual Studio Code but not in fcc Test area. Any ideas?

**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 regCheck = 0;
    var denomCheck = 0;
    var cashDeduct = 0;
    var chngDeduct = 0;
    for (let x = cid.length - 1; x >= 0; x--)
    {
        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--)
        {
            if (cid[y][1] > 0)
            {       
                regCheck = (cid[y][1] * 100);
                denomCheck = denomArr[y];
                if (denomCheck < changeDue)
                {
                    if (regCheck <= changeDue)
                    {
                        changeDue -= (regCheck);
                        changeArr.push(cid[y][0]);
                        changeArr.push(cid[y][1]);
                    } else if (regCheck > changeDue && denomCheck < changeDue)
                    {
                        cashDeduct = Math.floor(changeDue % denomCheck);
                        chngDeduct = changeDue - cashDeduct;
                        changeDue -= chngDeduct;
                        changeArr.push(cid[y][0]);
                        changeArr.push(chngDeduct / 100);
                    }
                }
            }
        }
    }
result.change = changeArr;
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:

What errors are you getting?

The test kicks out using these inputs your output should be…
When I enter the inputs listed, I get the outputs it says I should get.

That doesn’t give me anything more to go on. Every test? What does your output look like? I’m on my phone so it is hard for me to run your code myself.

This is 1 of the output errors from the test:

checkCashRegister(3.26, 100, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]) should return {status: "OPEN", change: [["TWENTY", 60], ["TEN", 20], ["FIVE", 15], ["ONE", 1], ["QUARTER", 0.5], ["DIME", 0.2], ["PENNY", 0.04]]}.

This is my input line:
`

console.log(checkCashRegister(3.26, 100, [[“PENNY”, 1.01], [“NICKEL”, 2.05], [“DIME”, 3.1], [“QUARTER”, 4.25], [“ONE”, 90], [“FIVE”, 55], [“TEN”, 20], [“TWENTY”, 60], [“ONE HUNDRED”, 100]]));

This is the output from that line: { status: ‘OPEN’, change: [ ‘TWENTY’, 60, ‘TEN’, 20, ‘FIVE’, 15, ‘ONE’, 1, ‘QUARTER’, 0.5, ‘DIME’, 0.2, ‘PENNY’, 0.04 ] }`

You know, looking at it this way, I can now see what the problem is. My code put the change into a single array instead of a 2 dimensional array. ["", 0, "", 0] instead of [['', 0], ['', 0]]. Thank You for your help.

1 Like