¿What is wrong with my code? "Cash Registrer"

Hello, I am on “the last exercise Cash Registrer in algoritms JavaScript”.
I check the numbers one by one with calculator .I supose they are fine; but the run test do not pass only in one example with “OPEN”…(write me in Spanish if you can…please)
¿Can you correct me please?¿what is wrong?

Hear is my code:

function checkCashRegister(price, cash, cid) {

  var myObject = {

    status : "OPEN",

    change : []

  };

  var vuelto = (cash-price);

  var caja = 0;

  for (var j=0; j<cid.length; j++){

    caja += cid[j][1];

  }

  if (vuelto === caja){

    myObject.status = "CLOSED";

    myObject.change = cid;

    return myObject;

  }else{

    if (vuelto > caja){

      myObject.status = "INSUFFICIENT_FUNDS";

      myObject.change = [];

      return myObject;

    }else{

      var moneda =[0.01, 0.05, 0.1, 0.25, 1, 5, 10, 20, 100];

      for (var i=cid.length-1; i>=0; i--){

        if (vuelto<moneda[i]){

          continue;

        }else{

          if (vuelto<cid[i][1]){

        var b = vuelto / moneda[i];

        var a = Math.trunc(b) * moneda[i];

        myObject.status = "OPEN";

        myObject.change.push([cid[i][0], a]);

        vuelto -= a; 

          }else{

            myObject.status = "OPEN";

            myObject.change.push([cid[i][0], cid[i][1]]);

            vuelto -= cid[i][1];

          }

          if (vuelto == 0){

            return myObject;

          }

        }

      }myObject.status = "INSUFFICIENT_FUNDS";

      myObject.change = [];

      return myObject;

    }

  } 

}

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]]);

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

Gracias por el dato!!
Respecto al algoritmo ¿hay algo que me falte o algo mal?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.