Cash Register is working! ...or not

Tell us what’s happening:
Hello everybody,

I need a little help because I feel a little bit lost…
My code seems working on my different browser’s consoles (chrome, safari, firefox). It returns exactly what the tests want but when I press “run the tests” on freeCodeCamp everything is wrong except the first (“should return an object.”)…:face_with_raised_eyebrow:
If somebody can explain to me what’s wrong, I would be very thankful !!! :blush:
(Sorry for my English) :woozy_face:


Your code so far

var argent = [
    {name: "PENNY", value: 0.01},
    {name: "NICKEL", value: 0.05},
    {name: "DIME", value: 0.1},
    {name: "QUARTER", value: 0.25},
    {name: "ONE", value: 1},
    {name: "FIVE", value: 5},
    {name: "TEN", value: 10},
    {name: "TWENTY", value: 20},
    {name: "ONE HUNDRED", value: 100}

function checkCashRegister(price, cash, cid) {
    var monnaie = {
        statut: "",
        change: []
    var moneyBack = cash - price;
    let cashInDrawer = 0;
    let rest = 0;

    for(var i=0; i<cid.length; i++) {
        cashInDrawer += cid[i][1];

    let variable = moneyBack;

    if (cashInDrawer < moneyBack) {
        monnaie.statut = "INSUFFICIENT_FUNDS";
        monnaie.change = [];
    } else if(cashInDrawer == moneyBack) {
        monnaie.statut = "CLOSED";
    } else if(cashInDrawer > moneyBack) {
        monnaie.statut = "OPEN";
        for(var j=cid.length-1; j>=0; j--) {
        if(cid[j][1]>0) {
                let max = cid[j][1]/argent[j].value;
                var n=0;
                for(var k=1; k<=max; k++) {
                        variable -= argent[j].value;
                        variable = Math.round(variable*100)/100;
                monnaie.change.push([cid[j][0], (n*argent[j].value)]);


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Safari/605.1.15.

Link to the challenge:

Object key should be status … looks like you may have spelled it incorrectly

1 Like

I’m getting values that differ from the expected results on at least one of the tests.

You don’t seem to be handling the case where the drawer is greater than change owed but you still cannot make proper change. If you have a ONE and a PENNY you cannot make .50 in change.

Also, you are returning an object with a property statut vs property status which may be a problem too.

1 Like

Thank you Kickflips!
It resolves 4 on 5 tests!!! :yum:
I wrote “status” in French… :grin:

Thank you Alhazen!!! Yes I wrote “satus” in French… :stuck_out_tongue_closed_eyes:
Now, 5 tests are ok… I’m going to work on the last one! :wink:

You’re welcome.
Excellent! It looked as if you were headed in the right direction with this. Good luck.