Help for this mistake

There is an error in the last part of the code that I can’t find. it is the part that calls the code, the part freeCodeCamp wrote. if anyone sees it let me know, please.

Your code so far


const REGISTER_STATUS = {closed :'Closed', insufficientFunds: 'INSUFFICIENT_FUNDS', open: 'Open'
}

function checkCashRegister(price, cash, cid) {
let cashRegister = {status: '', change: cid};
const changeNeeded = parseFloat(cash - price).tofixed(2);
const changeAvailable =getTotalCashRegisterChange(cid);
cashRegister.status =getTotalCashRegisterStatus(changeNeeded, changeAvailable);

If (cashRegister.status === REGISTER_STATUS.insufficientFunds); {
  cashRegister.change= [];
  return cashRegister;
} 
cashResgister.change=getCustomersChange(changeNeeded, cid);
if (changeNeeded > getTotalCashRegisterChange(changeRegister.change)){cashRegister.status = REGISTER_STATUS.insufficientFunds;
cashRegister.change = [];
}
if (cashRegister.status === REGISTER_STATUS.close){
 cashRegister.change = [...cid]
}
return cashRegister;
}
function getCustomersChange(changeNeeded, changeInDrawer){
const change = [];
const currencyDictionary ={
 "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 
};
for (let i =changeInDrawer.length - 1; i>= 0; i--) {
 const coinName = changeInDrawer[i][0];
 const coinTotal = changeInDrawer [i][1];
 const coinValue = currencyDictionary[coinName];
 let coinAmount = (coinTotal/ coinValue).tofixed(2);
 let coinToReturn = 0;

 while(changeNeeded >= coinValue && coinAmount > 0){
   changeNeeded -= coinValue;
   changeneeded = changeNeeded.toFixed(2);
   coinAmount --;
   coinToReturn ++;
 }
if (coinToReturn > 0) {
 change.push([coinName, coinToReturn * coinValue]);
}

}
return change;
}
function getTotalCashRegisterStatus(changeNeeded, changeAvailable){
 if(Number(changeNeeded) > Number(changeAvailable)){
   return REGISTER_STATUS.insufficientFunds;

if (Number(changeNeeded) > Number(changeAvailable)) {
 return Register_status.open;
}
return REGISTER_STATUS.closed;
}
function getTotalCashRegisterChange(changeInDrawer) {
  let total = 0;
  for (let change of changeInDrawer){
    let changeValue = change(1);
    total += changeValue;
  }
  return total.toFixed(2);

}
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 6.1; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0.

Challenge: Cash Register

Link to the challenge:

Nope, it is in the code you wrote. Try to indent your code and you should be able to figure it out.

also, you have some typos. There is no If statement, but there is an if statement.

Also, be careful of using global variables (like REGISTER_STATUS) which do not get reset between test cases.

// running tests
SyntaxError: unknown: Unexpected token (74:177)

72 |
73 |

74 | 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]]);
| ^
Build failed

Delete that line and you will get another error at a difference location. Trust me, you have some missing brackets in the code you added.

Made some correction. I can’t find the problem with “change” that is showing in the console as not a function.

const REGISTER_STATUS = {closed :'CLOSED', insufficientFunds: 'INSUFFICIENT_FUNDS', open: 'OPEN'
}

function checkCashRegister(price, cash, cid) {
 let cashRegister = {status: '', change: cid};
 const changeNeeded = parseFloat(cash - price).toFixed(2);
 const changeAvailable =getTotalCashRegisterChange(cid);{
 cashRegister.status = getTotalCashRegisterStatus(changeNeeded, changeAvailable);
 
 } 
 if (cashRegister.status === REGISTER_STATUS.insufficientFunds); {
   cashRegister.change= [];
   return cashRegister;
 } 
 cashResgister.change=getCustomersChange(changeNeeded, cid);

 if (changeNeeded > getTotalCashRegisterChange(changeRegister.change)){cashRegister.status = REGISTER_STATUS.insufficientFunds;
cashRegister.change = [];
 }
if (cashRegister.status === REGISTER_STATUS.close){
  cashRegister.change = [...cid]
  
}
 return cashRegister;

function getCustomersChange(changeNeeded, changeInDrawer){
const change = [];
const currencyDictionary ={
  "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 
};

for (let i =changeInDrawer.length - 1; i>= 0; i--) {
  const coinName = changeInDrawer[i][0];
  const coinTotal = changeInDrawer [i][1];
  const coinValue = currencyDictionary[coinName];
  let coinAmount = (coinTotal/ coinValue).toFixed(2);
  let coinToReturn = 0;

  while(changeNeeded >= coinValue && coinAmount > 0){
    changeNeeded -= coinValue;
    changeNeeded = changeNeeded.toFixed(2);
    coinAmount --;
    coinToReturn ++;
    }
    if (coinToReturn > 0) {
  change.push([coinName, coinToReturn * coinValue]);
  } 
  return change;
  }

 
}

function getTotalCashRegisterStatus(changeNeeded, changeAvailable){
  if(Number(changeNeeded) > Number(changeAvailable)){
    return REGISTER_STATUS.insufficientFunds;
  }
if (Number(changeNeeded) > Number(changeAvailable)) {
  return  REGISTER_STATUS.open;
}
return REGISTER_STATUS.closed;
}
 function getTotalCashRegisterChange(changeInDrawer) {
   let total = 0;
   for (let change of changeInDrawer){
     let changeValue = change(1);
     total += changeValue;
   }
   return total.toFixed(2)
   }
;
}

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]])
let changeValue = change(1);

In the line above, your syntax of change(1) is trying to call a function named change (which does not exist) and pass it the value 1 as an argument.

Idk im going to start over again :frowning: im just don’t get it.

What is change and what are you trying to accomplish in the line I referenced above.