Tell us what’s happening:
Describe your issue in detail here.
Can’t pass the third Objective. Please where am i getting it wrong.
**Your code so far**
function checkCashRegister(price, cash, cid) {
let currency = {
"ONE HUNDRED": 10000,
"TWENTY DOLLARS": 2000,
"TEN DOLLARS": 1000,
"FIVE DOLLARS": 500,
"DOLLAR": 100,
"QUARTER": 25,
"DIME": 10,
"NICKEL": 5,
"PENNY": 1
}
let change =cash *100 - price*100;
let cidTotal = 0
let result={
status:"",
change:[]
}
for(let i=0;i<cid.length;i++){
cidTotal += cid[i][1]*100
}
if(change > cidTotal){
result.status="INSUFFICIENT_FUNDS"
return result;
}else if(change == cidTotal){
result.status = "CLOSED"
result.change=cid
return result;
}else{
let answer = [];
cid = cid.reverse()
for(let item of cid){
let box = [item[0], 0]
item[1] = item[1]*100
while(change >= currency[item[0]] && item[1] > 0){
change -= currency[item[0]]
item[1] -= currency[item[0]]
box[1] += currency[item[0]] / 100
}
if(box[1]>0){
answer.push(box)
};
}
if(change > 0){
return {status: "INSUFFICIENT_FUNDS", change: []};
}
return {status: "OPEN", change: answer}
}
}
console.log(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]]));
console.log(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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36
Challenge: Cash Register
Link to the challenge: