Hello,
I am a single project away from getting the second certificate. Can anyone help me how can I go on from here with my code?
function checkCashRegister(price, cash, cid) {
let moneyInfo = [
{ type: "ONE HUNDRED", value: 100.0 },
{ type: "TWENTY", value: 20.0 },
{ type: "TEN", value: 10.0 },
{ type: "FIVE", value: 5.0 },
{ type: "ONE", value: 1.0 },
{ type: "QUARTER", value: 0.25 },
{ type: "DIME", value: 0.1 },
{ type: "NICKEL", value: 0.05 },
{ type: "PENNY", value: 0.01 }
];
let moneyTypes=["ONE HUNDRED","TWENTY","TEN","FIVE","ONE","QUARTER","DIME","NICKEL","PENNY"]
let moneyValues=[100.0,20.0,10.0,1.0,0.25,0.1,0.05,0.01]
//how much we owe after the transaction
let changeDue=cash-price;
changeDue=Math.round(changeDue * 100) / 100;
let ourRegister=[...cid];
//ourRegister is copy of cid with totalValueOfCid added as total
// total value of cash in cid
let totalValueOfCid=0;
let cidArr=Object.entries(cid).flat(99)
for(let i=2;i<cidArr.length;i=i+3){
totalValueOfCid+=cidArr[i];
}
totalValueOfCid = Math.round(totalValueOfCid * 100) / 100;
ourRegister.total=totalValueOfCid;
console.log(ourRegister)
let response={status: null, change: []};
if(changeDue>ourRegister.total){
response.status="INSUFFICIENT_FUNDS";
return response;
}
if(changeDue===ourRegister.total){
response.status="CLOSED";
response.change=cid;
return response;
}
let answer= "";
for (let i = 0; i < moneyValues.length; i++) {
while (moneyValues[i] <= changeDue) {
changeDue = changeDue-moneyValues[i];
answer = answer + moneyTypes[i];
}
}
response.status = "OPEN";
response.change = answer;
return response;
}
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]])
So