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