For the cash register project, I’m running into an issue with passing the 2 ‘status: “OPEN”’ checks. The code runs fine and returns the correct change, however, (I think) that the output format may not be matching with the acceptable answer.
The only difference that I can see between my output and the acceptable output is single quotes (’) in my output vs double quotes (") in the acceptable output which is given when the check fails.
For example for the second check my output is:
{ status: ‘OPEN’, change: [ [ ‘QUARTER’, 0.5 ] ] }
and the acceptable output in the error message is:
{status: “OPEN”, change: [[“QUARTER”, 0.5]]}
Any help/guidance will be greatly appreciated. Thanks.
**(My code is below)
var correctChange = [ ];
function checkCashRegister(price, cash, cid) {
var change = cash - price;
var roundedChange = change.toFixed(2);
var changeInDrawer = 0;
for(var i = 0; i<cid.length; i++){
changeInDrawer += cid[i][1];
};
if(changeInDrawer < roundedChange){
return {status: "INSUFFICIENT_FUNDS", change:[]};
} else {
if(changeInDrawer == roundedChange){
return {status: "CLOSED", change: cid};
} else {
let howMuchChange = {
"ONE HUNDRED": [cid[8][1],100],
"TWENTY": [cid[7][1],20],
"TEN": [cid[6][1],10],
"FIVE": [cid[5][1],5],
"ONE": [cid[4][1],1],
"QUARTER": [cid[3][1],.25],
"DIME": [cid[2][1],.10],
"NICKEL": [cid[1][1],.05],
"PENNY": [cid[0][1],.01]
};
let variableKey=0;
let i = 0;
let variable_value;
let pushedchange = 0;
for(var value in howMuchChange){
variable_value = value;
if(roundedChange >= Object.values(howMuchChange)[i][1]) { if(roundedChange >= Object.values(howMuchChange)[i][0]){
correctChange.push([variable_value, Object.values(howMuchChange)[i][0]]);
roundedChange -= Object.values(howMuchChange)[i][0];
Object.values(howMuchChange)[i][0]-=Object.values(howMuchChange)[i][0]
} else{
if(roundedChange <= Object.values(howMuchChange)[i][0]){
pushedchange = roundedChange -( roundedChange%Object.values(howMuchChange)[i][1])
correctChange.push([variable_value, pushedchange]);
roundedChange -= pushedchange;
roundedChange = roundedChange.toFixed(2);
}
}
} i+=1;
};
if(roundedChange > 0 ){
return {status: "INSUFFICIENT_FUNDS", change:[]};
} if (roundedChange == 0){
return { status: "OPEN", change: correctChange};
};
};
};
}
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]]))
*End Code