JavaScript Algorithms and Data Structures Projects - Cash Register

Tell us what’s happening:
Describe your issue in detail here.
Ok so I have typed out my solution into the test and it says that my code fails one of them. I tried all of the invocations that the test shows you it plans to try on my end. They all passed on my end. My code results are the exact same as what is expected so what do we think happened? I am not even sure where to go from here because I don’t have a clue what caused it to fail in the first place.
Is there anyone who could help me see what I am missing here I would truly appreciate the help! :slight_smile:
Your code so far

function checkCashRegister(price, cash, cid) {
let [penny,nickel,dime,quarter,one,five,ten,twenty,hundred] = cid;
let registerTotal = ((penny[1] * 100) + 
                     (nickel[1] * 100) + 
                     (dime[1] * 100) + 
                     (quarter[1] * 100) +
                     (one[1] * 100) + 
                     (five[1] * 100) + 
                     (ten[1] * 100) + 
                     (twenty[1] * 100) + 
                     (hundred[1] * 100));
let changeDue = ((cash * 100) - (price * 100));
let changeGiven = [];

let calcs = (changeDue / 20) / 100;
let denomTotal = Math.floor(calcs) * 20;
if(calcs >= 1){
 if(denomTotal <= twenty[1]){
   changeGiven.push([twenty[0],denomTotal]);
   changeDue -= (denomTotal * 100);
   registerTotal -= (denomTotal * 100);
 }else{
   changeGiven.push([twenty[0],twenty[1]]);
   changeDue -= (twenty[1] * 100);
   registerTotal -= (twenty[1] * 100);
 }
}
calcs = (changeDue / 10) / 100;
denomTotal = Math.floor(calcs) * 10;
if(calcs >= 1){
 if(denomTotal <= ten[1]){
   changeGiven.push([ten[0],denomTotal]);
   changeDue -= (denomTotal * 100);
   registerTotal -= (denomTotal * 100);
 }else{
   changeGiven.push([ten[0],ten[1]]);
   changeDue -= (ten[0] * 100);
   registerTotal -= (ten[1] * 100);
 }
}
calcs = (changeDue / 5) / 100;
denomTotal = Math.floor(calcs) * 5;
if(calcs >= 1){
 if(denomTotal <= five[1]){
   changeGiven.push([five[0],denomTotal]);
   changeDue -= (denomTotal * 100);
   registerTotal -= (denomTotal * 100);
 }else{
   changeGiven.push([five[0],five[1]]);
   changeDue -= (five[1] * 100);
   registerTotal -= (denomTotal * 100);
 }
}
calcs = (changeDue / 1) / 100;
denomTotal = Math.floor(calcs) * 1;
if(calcs >= 1){
 if(denomTotal <= one[1]){
   changeGiven.push([one[0],denomTotal]);
   changeDue -= (denomTotal * 100);
   registerTotal -= (denomTotal * 100);
 }else{
   changeGiven.push([one[0],one[1]]);
   changeDue -= (one[0],one[1]);
   registerTotal -= (one[1] * 100);
 }
}
calcs = changeDue / (.25 * 100);
denomTotal = (Math.floor(calcs) * (.25 * 100)) / 100;
if(calcs >= 1){
 if(denomTotal <= quarter[1]){
   changeGiven.push([quarter[0],denomTotal]);
   changeDue -= (denomTotal * 100);
   registerTotal -= (denomTotal * 100);
 }else{
   changeGiven.push([quarter[0],denomTotal]);
   changeDue -= (quarter[1] * 100);
   registerTotal -= (quarter[1] * 100);
 }
}
calcs = changeDue / (.10 * 100);
denomTotal = (Math.floor(calcs) * (.10 * 100)) / 100;
if(calcs >= 1){
 if(denomTotal <= dime[1]){
   changeGiven.push([dime[0], denomTotal]);
   changeDue -= (denomTotal * 100);
   registerTotal -= (denomTotal * 100);
 }else{
   changeGiven.push([dime[0],dime[1]]);
   changeDue -= (dime[1] * 100);
   registerTotal -= (dime[1] * 100);
 }
}

calcs = changeDue / (.05 * 100);
denomTotal = (Math.floor(calcs) * (.05 * 100)) / 100;
if(calcs >= 1){
 if(denomTotal <= nickel[1]){
   changeGiven.push([nickel[0],denomTotal]);
   changeDue -= (denomTotal * 100);
   registerTotal -= (denomTotal * 100);
 }else{
   changeGiven.push([nickel[0],nickel[1]]);
   changeDue -= (nickel[1] * 100);
   registerTotal -= (nickel[1] * 100);
 }
}
calcs = changeDue / (.01 * 100);
denomTotal = (Math.floor(calcs) * (.01 * 100)) /100;
if(calcs >= 1){
 if(denomTotal <= penny[1]){
   changeGiven.push([penny[0], denomTotal]);
   changeDue -= (denomTotal * 100);
   registerTotal -= (denomTotal * 100);
 }else{
   changeGiven.push(penny[0],penny[1]);
   changeDue -= (penny[1] * 100);
   registerTotal -= (penny[1] * 100);
 }
}
if(changeDue === 0 && registerTotal === 0){
 return {status:"CLOSED", change:cid};
}else if(changeDue === 0){
 return {status:"OPEN", change:changeGiven};
}else if(changeDue !== 0){
 return {status:"INSUFFICIENT_FUNDS",change:[]}
}
}

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]]);
   **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0

Challenge: JavaScript Algorithms and Data Structures Projects - Cash Register

Link to the challenge:

I’ve checked the failing test and function is returning different answer than expected for me - { status: 'INSUFFICIENT_FUNDS', change: [] }.

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]]));

This is a certification project, so the amount of help we are going to give you is limited. I do have one question. You initially do the following:

let changeDue = ((cash * 100) - (price * 100));

What unit is the value of changeDue stored in?

Then a few lines later you do:

let calcs = (changeDue / 20) / 100;

Are all of the units being used here correct?

Thank you for your reply, I had the wrong number when I was accessing an array. I should have taken more time to look over the code that I typed in for the answer. My troubleshooting skills apparently need some work hah. Thanks for the help, I truly appreciate it :smiley:

Yea I was trying to use whole numbers to do all of the calculations for accuracy and as far as that part went it was all working correctly. I simply put the wrong number when trying to access an array. Thank you for your reply though. :grinning: