Tell us what’s happening:
I am wondering what the best way would be to subtract the denominations for the cid value. Any tips would be appreciated.As of right now I can past 3 out of 5 tests.
Your code so far
function checkCashRegister(price, cash, cid) {
var cashAvailable = 0;
var changeOwed = cash-price;
var change = {
'One-Hundred':100,
'Twenty':20,
'Ten':10,
'Five':5,
'Dollar':1,
'Quarter':0.25,
'Dime':0.1,
'Nickel':0.05,
'penny':0.01
}
var noFunds = {
status:"INSUFFICIENT_FUNDS",
change: []
};
var closed = {
status:"CLOSED",
change:cid
};
var flatt = cid.reduce(
function(acc, curr){
return acc.concat(curr);
})
for(var i = 0; i<flatt.length; i++){
if(typeof flatt[i] === "number"){
cashAvailable += flatt[i];
}
}
cashAvailable = Math.round(100*cashAvailable)/100
if(cashAvailable < changeOwed){
return noFunds;
}else if(cashAvailable === changeOwed){
return closed;
}
//the below code is for coins only and changeOwed is less than one dollar.
var coins = 0;
for(var i = 3; i>=0;i--){
if(cid[i][1] > 0.00){
coins += cid[i][1];
}
}
if(changeOwed > coins && changeOwed < 1.00){
return noFunds;
};
}
checkCashRegister(19.5, 20, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 1], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36
.
Link to the challenge: