In the last test show like i fail but wen i see, the console the answer is the same i dont understand what is failing HELP!
. sorry for my english
function checkCashRegister(price, cash, cid) {
var dic=cid.reverse();
var turn=[["PENNY", 0.01], ["NICKEL", 0.05], ["DIME", 0.1], ["QUARTER", 0.25], ["ONE", 1], ["FIVE", 5], ["TEN", 10], ["TWENTY", 20], ["ONE HUNDRED", 100]];
var change = cash-price; // get change
var temp=0.0;
var money=0.0;
var mult=0;
var anschange=[];
var totalcid = cid.map((a) => a[1]).reduce((a,b) => a+b,0); // get the total in cid
if(change >totalcid){
return {status: "INSUFFICIENT_FUNDS", change:[]};
}
console.log(price, cash, cid); //--only test
if(change == totalcid){ // the problem?
console.log({status: "CLOSED", change: cid}) //--only test
return {status: "CLOSED", change: cid};
}
for(var i in dic){
temp=Math.floor(change/turn.find((a)=>a[0]==dic[i][0])[1]); // get the number of coins we ned (specific value)
money=dic[i][1]/turn.find((a)=>a[0]==dic[i][0])[1]; // get the number of coins we have (specific value)
if(change > 0){
if(money >= temp){
mult = temp
}else{
mult = temp - money;
mult = temp - mult;
}
if(mult*dic[i][1]>0){
change-=mult*turn.find((a)=>a[0]==dic[i][0])[1];
change=Math.round(change *100)/100;
anschange.push([dic[i][0],mult*turn.find((a)=>a[0]==dic[i][0])[1]]);
}
}
if(change>0 && i == cid.length-1){
return {status: "INSUFFICIENT_FUNDS", change:[]};
}
}
return {status: "OPEN", change: anschange};
}
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/90.0.4430.72 Safari/537.36
Challenge: Cash Register
Link to the challenge: