Trouble with finishing Exact Change challenge

Trouble with finishing Exact Change challenge
0

#1

Hey there. I’ve been working away on this challenge for a bit now and I feel(keyword haha) that I am close to the answer. The 2 main problems I’m having is getting the money from the drawer to subtract despite trying to code it to. My other problem is that I’m not really sure how to return the final answer they require of each bill to give. Any help is much appreciated!

> function checkCashRegister(price, cash, cid) {
>   var change;
>   var changeCurrency = [];
>   //variable shortcuts for each set of money type
>   var hundred = arguments[2][8][1];
>   var twenty = arguments[2][7][1];
>   var ten = arguments[2][6][1];
>   var five = arguments[2][5][1];
>   var one = arguments[2][4][1];
>   var quarter = arguments[2][3][1];
>   var dime = arguments[2][2][1];
>   var nickel = arguments[2][1][1];
>   var penny = arguments[2][0][1];
>   
>   //total amount of money in the drawer
>   var totalDrawer = hundred + twenty + ten + five + one + quarter + dime + nickel + penny;
>   
>   //figures out the change needed back
>   change = cash - price;
>   
>   //while the change required is more than 0 the loop will continue subtracting money from change using the available bills
>   while(change>0) {
>   //itterates through each currency, if the change needed is higher than that bill AND bills of that currency still exists in the drawer, then it subtracts that bill from the change amount and the register
>     if(change >= 100 && hundred !== 0) {
>       change = change - 100; 
>       hundred = hundred - 100;
>     } 
>     else if(change >= 20 && twenty !== 0) {
>       change = change - 20;
>       twenty = twenty - 20;
>     } 
>     else if(change >= 10 && ten !== 0) {
>       change = change - 10;
>       ten = ten - 10;
>     } 
>     else if(change >= 5 && five !== 0) {
>       change = change - 5;
>       five = five - 5;
>     } 
>     else if(change >= 1 && one !== 0) {
>       change = change - 1;
>       one = one - 1;
>     } 
>     else if(change >= 0.25 && quarter !== 0) {
>       change = change - 0.25;
>       quarter = quarter - 0.25;
>     } 
>     else if(change >= 0.10 && dime !== 0) {
>       change = change - 0.10;
>       dime = dime - 0.10;
>     } 
>     else if(change >= 0.05 && nickel !== 0) {
>       change = change - 0.05;
>       nickel = nickel - 0.05;
>     } 
>     else if(change >= 0.01 && penny !== 0) {
>       change = change - 0.01;
>       penny = penny - 0.01;
>     } 
>     //if the change required is exactly how much money is in the drawer, it closes the cash register
>     if(change === totalDrawer) {
>       return "Closed";
>     } 
>     //if the change required is bigger than the money in the drawer, it says it lacks the funds needed to pay the change back
>     else if(change > totalDrawer) {
>       return "Insufficient Funds";
>     }
>   }
>   return "put final answer here";
> }

checkCashRegister(19.50, 20.00, [[“PENNY”, 1.01], [“NICKEL”, 2.05], [“DIME”, 3.10], [“QUARTER”, 4.25], [“ONE”, 90.00], [“FIVE”, 55.00], [“TEN”, 20.00], [“TWENTY”, 60.00], [“ONE HUNDRED”, 100.00]]);