Here is the problem is known as Cash Register.
I solved this and got a certificate

But, my code is pretty big.
Please suggest to me a better way to fix this, if you have some.
Here is my code below,
function checkCashRegister(price, cash, cid) {
let x = cash-price;
let budget = {};
for(let i=0; i<cid.length; i++){
budget[cid[i][0]] = cid[i][1];
}
let result =[];
let eqObj = {status: "CLOSED", change: cid};
let insaObj = {status: "INSUFFICIENT_FUNDS", change: []};
let valBug = Object.values(budget);
let sum = 0;
for(let i=0; i<valBug.length; i++){
sum += valBug[i];
}
if(x===sum){
return eqObj;
}else if(x>sum){
return insaObj
}else{
if(x>100){
let c = Math.min(Math.floor(x/100),Math.floor(budget["ONE HUNDRED"]/100));
if(budget["ONE HUNDRED"] >= c && c!= 0){
result.push(["ONE HUNDRED", c*100]);
x = (x-(c*100)).toFixed(2);
}else{
return insaObj;
}
}
if(x>20){
let c = Math.min(Math.floor(x/20),Math.floor(budget["TWENTY"]/20));
if(budget["TWENTY"] >= c && c!= 0){
result.push(["TWENTY", c*20]);
x = (x-(c*20)).toFixed(2);
}else{
return insaObj;
}
}
if(x>10){
let c = Math.min(Math.floor(x/10),Math.floor(budget["TEN"]/10));
if(budget["TEN"] >= c && c!= 0){
result.push(["TEN", c*10]);
x = (x-(c*10)).toFixed(2);
}else{
return insaObj;
}
}
if(x>5){
let c = Math.min(Math.floor(x/5),Math.floor(budget["FIVE"]/5));
if(budget["FIVE"] >= c && c!= 0){
result.push(["FIVE", c*5]);
x = (x-(c*5)).toFixed(2);
}else{
return insaObj;
}
}
if(x>1){
let c = Math.min(Math.floor(x/1),Math.floor(budget["ONE"]/1));
if(budget["ONE"] >= c && c!= 0){
result.push(["ONE", c*1]);
x = (x-(c*1)).toFixed(2);
}else{
return insaObj;
}
}
if(x>0.25){
let c = Math.min(Math.floor(x/0.25),Math.floor(budget["QUARTER"]/0.25));
if(budget["QUARTER"] >= c && c!= 0){
result.push(["QUARTER", c*0.25]);
x = (x-(c*0.25)).toFixed(2);
}else{
return insaObj;
}
}
if(x>0.10){
let c = Math.min(Math.floor(x/0.10),Math.floor(budget["DIME"]/0.10));
if(budget["DIME"] >= c && c!= 0){
result.push(["DIME", c*0.10]);
x = (x-(c*0.10)).toFixed(2);
}else{
return insaObj;
}
}
if(x>0.05){
let c = Math.min(Math.floor(x/0.05),Math.floor(budget["NICKEL"]/0.05));
if(budget["NICKEL"] >= c && c!= 0){
result.push(["NICKEL", c*0.05]);
x = (x -(c*0.05)).toFixed(2);
}else{
return insaObj;
}
}
if(x > 0.01){
let c = Math.min(Math.floor(x/0.01),Math.floor(budget["PENNY"]/0.01));
if(budget["PENNY"] >= c*0.01 && c!= 0){
result.push(["PENNY", c*0.01]);
x = (x - (c*0.01)).toFixed(2);
}else{
return insaObj;
}
}
}
return {status: "OPEN", change: result};
}
I will try to use descriptive variable names next time.