I desperately need a help

Tell us what’s happening:
Hi all. I haven’t finish writing my code and obviously it doesn’t work .
I feel like I’m almost there but I don’t know how to get there…
Is anybody can help me recall some hint and tips I’ll be thankful.
Perhaps I should restart from the beginning I can accept that truth with a bit of pain.
Thank you!
Your code so far


function checkCashRegister(price, cash, cid) {
 var change = Math.round((cash - price)*100);
 var currency = [1, 5, 10, 25, 100, 500, 1000, 2000, 10000];
 var sum = 0;
 var finCid = []; var value = [];
 var sumOfCid = function(cid){
   var mapCid = cid.map(x => Math.round(x[1]*100));
   for(var i = 0; i < mapCid.length; i++){
     if(change >= currency[i]) {
       sum += mapCid[i]
     }   
   }; return sum;
 }; 
var leftCurr = sumOfCid(cid) 
 if(change === leftCurr) {
   return{status: "CLOSED", change: cid};
 } else if (change > leftCurr) {
   return{status: "INSUFFICIENT_FUNDS", change: []};
 } else {
   for (var i = currency.length - 1; i > -1; i--){
     while(change >= currency[i]){
       change -= currency[i];
       cid[i][1] -= (currency[i])/100;
       value.push([cid[i][0], ])
       return {status: "OPEN", change: value}
     } 
   }  
 }
}
console.log(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(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]]));
console.log(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_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36.

Challenge: Cash Register

Link to the challenge:

1 Like

in case you feel stuck, you can always check the hint section of each lesson.

Hi @bigclown. yeah I checked it but I just want to know if there’s any way I can develop my approach to pass the challenge! Anyway I am going to read it again !

1 Like

sure it can work, you just need to find what you put in the wrong place

You can use this to look at what happens at each line of your code:
http://pythontutor.com/javascript.html

1 Like

Thank you @ilenia! I will give it a try again. Just one step left for my second fcc certification!