Help please, I'm stuck :( Cash Register Challenge

Tell us what’s happening:

Your code so far


function checkCashRegister(price, cash, cid) {
  var change=cash-price;
  var values = [0.01,0.05,0.1,0.25,1,5,10,20,100]
  var array = cid ;
  var cashes = array.map(i=>i[1])
  var total = cashes.reduce((a,b)=>a+b);
  var posibles = values.filter(i=>i<change);
  var reales = []
  var aux=0;
  var auxarray=[];
  var nombres=array.map(i=>i[0]);
  for(let i = 0; i < posibles.length;i++){reales[i]= cashes[i] }
  var total1 = reales.reduce((a,b) => a+b);
  console.log(nombres)
  console.log(total1);

  console.log(change);



  console.log(posibles);
  console.log(reales)

  if(change>total1){
    return {
      status:"INSUFFICIENT_FUNDS",
      change:[]
      }
  }
  else if(change==total){

    return {
      status:"CLOSED",
      change:cid
    }

  }
  else{

    for(let i = posibles.length-1;i=>0;i--){
      console.log(i)
    
      change=Number((change).toFixed(2));
      if(change>posibles[i]){
      aux=change/posibles[i]
     
      aux=Math.floor(aux)
    
      while(aux*posibles[i]>reales[i]){aux=aux-1}
      console.log(aux)
      auxarray.push(nombres[i],aux*posibles[i])  
      if(change- aux*posibles[i]>=0){change=change- aux*posibles[i]}
    }
      console.log(change)
      if(i==0){break}
    }
    console.log([auxarray]);
  return {status:"OPEN", change:[auxarray]}
  }
  
  
  // Here is your change, ma'am.
}
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]])

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.75 Safari/537.36.

Link to the challenge:

ok guys i think everything is alright but im not passing the third test, and when i console log the array its how its supposed to be. sorry for my bad english, can somebody help me please? I’ve been stuck here for like a week

what you are returning is in the wrong format,
you are returning this

{
  "status": "OPEN",
  "change": [
    ["TWENTY", 60, "TEN", 20, "FIVE", 15, "ONE", 1, "QUARTER", 0.5, "DIME", 0.2, "PENNY", 0.04]
  ]
}

you should be returning this:

{
  status: "OPEN",
  change: [
    ["TWENTY", 60],
    ["TEN", 20],
    ["FIVE", 15],
    ["ONE", 1],
    ["QUARTER", 0.5],
    ["DIME", 0.2],
    ["PENNY", 0.04]
  ]
}

Thank you for your reply! Nobody else answered :frowning: . And yeah, I fixed it a few hours after. It was such a silly mistake

What do you think about my answer?

do you really need all those variables?
anyway, you could make your code much more readable if you were to use more descriptive names, and more comments to describe what’s happening in your code

You’re right about comments, and I’m sorry if the names of the variables seem odd; it’s just that I’m a native spanish speaker and I mixed the spanish with the english while naming things. I’ll keep in mind those errors for my coding in the future. I appreciate a lot your reply!