Tell us what’s happening:
I wrote a code to calculate the change to be returned, before checking the cash in register. the idea is to then check the cash in the registerr and take out account to the cash available, which i intend to use the provided cahs in register array.
The problem i am facing is even when i try to see how to get the change required it doesnt balance with the tenders availbale.
Your code so far
WARNING
The challenge seed code and/or your solution exceeded the maximum length we can port over from the challenge.
You will need to take an additional step here so the code you wrote presents in an easy to read format.
Please copy/paste all the editor code showing in the challenge from where you just linked.
function checkCashRegister(price, cash, cid) {
const box = [
{'status': 'INSUFFICIENT_FUNDS', 'change': []},
{'status':'CLOSED', 'change': []},
{'status':'OPEN', 'change': []}
];
let tellerSort = {
0.01 : 'PENNY',
0.05 : 'NICKEL',
0.1 : 'DIME',
0.25 : 'QUARTER',
1 : 'ONE',
5 : 'FIVE',
10 : 'TEN',
20 : 'TWENTY',
100 : 'ONE HUNDRED'
};
let change = cash - price;
let bag = [];
let returnChange = function(change){
let check = change;
let count = 0;
if(check > 100){
count = Math.floor(check/100);
let tap = 100*count ;
let send = [[tellerSort[100], tap]];
//get the remiander and process it
bag.push(send);
returnChange(check % 100);
}
if(check < 100 && check > 20){
count = Math.floor(check/20);
let tap = 20*count ;
let send = [tellerSort[20], tap];
//get the remiander and process it
bag.push(send);
returnChange(check % 20);
// return [tellerSort[20], tap];
}
if(check < 20 && check > 10){
count = Math.floor(check/10);
let tap = 10*count;
let send = [tellerSort[10], tap];
// add the new count on the bag
bag.push(send);
//get the remainder and process it
returnChange(check % 10);
}
if(check < 10 && check > 5){
count = Math.floor(check/5);
let tap = 5*count;
// add the new count on the bag
let send = [tellerSort[5], tap];
bag.push(send);
//get the remainder and process it
returnChange(check % 5);
}
if(check < 5 && check > 1){
count = Math.floor(check/1);
let tap = 1*count;
// add the new count on the bag
let send = [tellerSort[1], tap];
bag.push(send);
//get the remainder and process it
returnChange(check % 1);
}
if(check < 1 && check > 0.25){
count = Math.floor(check/0.25);
let tap = 0.25*count;
// add the new count on the bag
let send = [tellerSort[0.25], tap];
bag.push(send);
//get the remainder and process it
returnChange(check % 0.25);
}
if(check < 0.25 && check > 0.1){
count = Math.floor(check/0.1);
let tap = 0.1*count;
// add the new count on the bag
let send = [tellerSort[0.1], tap];
bag.push(send);
//get the remainder and process it
returnChange(check % 0.1);
}
if(check < 0.1 && check > 0.05){
count = Math.floor(check/0.05);
let tap = 0.05*count;
// add the new count on the bag
let send = [tellerSort[0.05], tap];
bag.push(send);
//get the remainder and process it
returnChange(check % 0.05);
}
if(check < 0.05 && check > 0.01){
count = Math.floor(check/0.01);
let tap = 0.01*count;
// add the new count on the bag
let send = [tellerSort[0.01], tap];
bag.push(send);
//get the remainder and process it
returnChange(check % 0.01);
}
// return 'not covered';
// return Array.isArray(bag);
return bag;
}
// return change;
return returnChange(change);
}
let result = 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]]);
console.log(result);
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36
Challenge: JavaScript Algorithms and Data Structures Projects - Cash Register
Link to the challenge: