What’s happening:
My code returns a single-quoted string for the currency denominations(I don’t think a ten is called a denomination now that I think about it). I get a returned single quote, but when I use the google console, I get a double quote.
also, I could be using the wrong tool to get my solution.
Your code so far
function checkCashRegister(price, cash, cid) {
//variables first
let change = cash - price;
let registerArr = [];
let returnChange = 0;
let values = [100,20,10,5,1,.25,.1,.05,.01];
let valuesDenom = [100,20,10,5,1,.25,.1,.05,.01];
let registerTotal = 0;
let registerReturn = ["ONE HUNDRED","TWENTY","TEN","FIVE","DOLLAR","QUARTER","DIME","NICKEL", "PENNY"];
let resultingArr = [];
let status = "";
//take register, place it in a variable
//from highest value to lowest
let regValues = (arrayVals) => {
registerArr.unshift(arrayVals[1]);
};
cid.forEach(regValues);
//determine if the change is in the register
let reduction = (total, num) => {
return total + num;
}
registerTotal += registerArr.reduce(reduction);
//This function reduces values appropriately
let calculations = (value, index) =>{
var currentDenomChange = 0;
if(change > 0){
if(change >= values[index]) {
do{
change = (change - values[index]).toFixed(2);
currentDenomChange = currentDenomChange + values[index];
returnChange = (((returnChange * 100) + (values[index]*100))/100).toFixed(2);
//registerReturn.push([values[index]])
//console.log(change + " and " + returnChange);
}while(change >= values[index]);
resultingArr.push([registerReturn[index],currentDenomChange]);
// console.log(resultingArr);
}
}
}
//determines if the function will have
//equal, less or just enough money in the drawer
if (registerTotal > change){
status = "OPEN";
registerArr.forEach(calculations);
}else if (registerTotal == change){
status = "CLOSED";
registerArr.forEach(calculations);
} else {
status = "INSUFFICIENT_FUNDS";
resultingArr = [];
//console.log("no money");
}
let finalReveal = new Map();
finalReveal['status'] = status;
finalReveal['change'] = resultingArr;
//console.log(finalReveal);
return finalReveal;
}
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]]));
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]]);
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]]);
checkCashRegister(19.5, 20, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]);
checkCashRegister(19.5, 20, [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36
.
Challenge: Cash Register
Link to the challenge: