JavaScript Algorithms and Data Structures Projects - Cash Register

I’m failing my 3rd check. it is not workig. else if last condition is not working. i have given below the check

function checkCashRegister(price, cash, cid) {
const UNIT_AMOUNT = {
  "PENNY": 0.01,
  "NICKEL": 0.05,
  "DIME": 0.10,
  "QUARTER": 0.25,
  "ONE": 1.00,
  "FIVE": 5.00,
  "TEN": 10.00,
  "TWENTY": 20.00,
  "ONE HUNDRED": 100.00
}; 



let changedue = cash - price;
changedue = changedue.toFixed(2);
let changeArr = [];

let totalcid = 0;
for (let i = 0; i < cid.length; i++)
{
   totalcid += cid[i][1];
}
totalcid = totalcid.toFixed(2);
//console.log(totalcid);

if (totalcid < changedue)
{
  return {status: "INSUFFICIENT_FUNDS", change: []};
}
else if ( changedue === totalcid)
{
    return {status: "CLOSED", change: cid};
}
else if (changedue < totalcid)
{ 
   cid = cid.reverse();
  
  for (let element of cid) 
  {
    let temp = [element[0], 0];
 
    
    while (changedue >= UNIT_AMOUNT[element[0]] && element[1] > 0) 
    {
       
      temp[1] += UNIT_AMOUNT[element[0]];
      element[1] -= UNIT_AMOUNT[element[0]];
      changedue -= UNIT_AMOUNT[element[0]];
      //changedue = changedue.toFixed(2);
    }
    if (temp[1] > 0) 
    {
      changeArr.push(temp);
    }
  }
     
}
if (changedue > 0) {
  return { status: "INSUFFICIENT_FUNDS", change: [] };
}
console.log(changeArr);
return { status: "OPEN", change: changeArr};
}

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

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36

Challenge: JavaScript Algorithms and Data Structures Projects - Cash Register

Link to the challenge:

One of the ways i check for problems is sometimes just tossing a console.log in places with a string inside it describing the location it is at. If that string pops up in the console that means the code is being run there, when sometimes i don’t want that code being run.

If the 3rd test is not passing call the function with those values and put a console log around that function call to see its return. That will give you a good hint where to start putting your console logs to help hunt down your problem.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.