Tell us what’s happening:
Describe your issue in detail here.
My output for test three seems to be identical with the desired output but for some reason the test is not passing.
I know that I haven’t finished the last test stuff yet.
Can someone explain to me why this isn’t working?
**Your code so far**
function checkCashRegister(price, cash, cid) {
let status = "";
if(price < cash){
status = "OPEN";
}else if(price == cash){
status = "CLOSED";
}
let cid2 = cid;
let numbercurtype = 8;
while(iterating(cid2, numbercurtype)){
cid2[numbercurtype][1] *=100;
numbercurtype --;
}
let cashcalc = Math.round((cash - price)*100);
console.log(cashcalc);
let change = [];
if(status == "OPEN"){
change = checksmallerchange(8, cashcalc, cid, []);
if(change == -1){
status = "INSUFFICIENT_FUNDS";
change = [];
}
}
console.log({status:status, change:change})
return {status:status, change:change}
}
function checksmallerchange(type, changeneeded, cid2, changesofar){
if(type == -1){
return -1;
}
let changetype = [1, 5, 10, 25, 100, 500, 1000, 2000, 10000];
let changename = ["PENNY", "NICKEL", "DIME", "QUARTER", "DOLLAR", "FIVE", "TEN", "TWENTY", "HUNDRED"];
//calculate the amount of change needed of type
let changeamt = (changeneeded) % (changetype[type]);
console.log(`changeamt: ${changeamt}`);
changeamt = (changeneeded) - changeamt;
console.log(cid2[type][1] + " and " + changeamt);
if(cid2[type][1] >= changeamt){
console.log(cid2[type][1] + " and " + changeamt);
cid2[type][1] -= changeamt;
changeneeded -= changeamt;
if(changeamt!=0){
changesofar.push([changename[type], changeamt/100]);
console.log(changesofar);
}
}else if(cid2[type][1] !=0){
console.log(cid2[type][1]);
changeneeded -= cid2[type][1];
if(changeamt!=0){
changesofar.push([changename[type], cid2[type][1]/100]);
console.log(changesofar);
}
cid2[type][1] = 0;
}
console.log(changeneeded);
if(changeneeded == 0.0){
//console.log(changesofar);
//console.log (`changesofar = ${changesofar}`);
return changesofar;
}
return checksmallerchange(type-1, changeneeded, cid2, changesofar);
}
function iterating(cid, typecur){
if(typecur != -1){
return true;
}
return false;
}
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/91.0.4472.106 Safari/537.36
Challenge: Cash Register
Link to the challenge: