Javascript Progect. Cash register error getTotalCash RegisterStatus not define at checkCashRegister

Javascript Progect. Cash register error getTotalCash RegisterStatus not define at checkCashRegister
0
const REGISTER_NATURE={closed:"CLOSED",insufficient:"INSUFFFICIENT_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=getTotalCashStatus(changeNeeeded,changeAvailable);
console.log(cashRegister.status);
if(cashRegister.status===REGISTER_NATURE.insufficient){
cashRegister.change=[];
}
return cashRegister;
cashRegister.change=getYourChange(changeNeeded,cid);

if(changeNeeded>getTotalCashRegisterChange(cashRegister,change)){
cashRegister.status=REGISTER_NATURE.insufficient;
cashRegister.change=[];
}
if(cashRegister.status===REGISTER_NATURE.closed){
cashRegister.change=[...cid];
}
return cashRegister;
}
function getYourChange(changeNeeded,changeInDrawer){
constchange=[];
constBILLS={
"PENNY":0.01,
"NICKEL":0.05,
"DIME":0.10,
"QUARTER":0.25,
"ONE":1.00,
"FIVE":5.00,
"TEN":10.00,
"TWENTY":20.00,
"ONEHUNDRED":100.00
};
for(leti=changeInDrawer.length-1;i>=0;i--){
const bilName=changeInDrawer[i][0];
const bilTotal=changeInDrawer[i][1];
const bilValue=BILLS[bilName];
let bilAmount=(bilTotal/bilValue).toFixed(2);
let bilToReturn=0;
while(changeNeeded>=bilValue&&bilAmount>0){
changeNeeded-=bilValue;
changeNeeded=changeNeeded.tofixed(2);
bilAmount--;
bilToReturn++;
}
if(bilToReturn>0){
change.push([bilName,bilToReturn*bilValue]);
}
}
return change;
}
functiongetTotalRegisterStatus(changeNeeded,changeAvailable){
if(Number(changeNeeded)>Number(changeAvailable)){
return REGISTER_NATURE.insufficient;
if(Number(changeNeeded)<Number(changeAvailable)){
return REGISTER_NATURE.open;
}
return REGISTER_NATURE.closed;
}
functiongetTotalCashRegisterChange(changeInDrawer){
let total=0;
for(letchangeofchangeInDrawer){
let changeV=change[1];
total+=changeV;
}
return total.toFixed(2);
}

could you please expand in what errors you get?

It seems there is a problem in line 6. Because the i can’t console anything from then. On freecode Camp it failed all test, when i am trying to console anything below line 6

CashRegister.status = getTotalCashStatus(ChangeNeeded,changeAvailable)

It’s saying that function is not defined in checkCashRegister()

In the code you have posted, you have many syntax errors. You are missing important spaces between the keyword function and the function’s name. Also, one of your for loops looks like for(letchangeofchangeInDrawer){ That is not proper syntax. Again, you are missing spaces between key words.

One of the biggest problems of your code is that it lacks any kind of indentation formatting. It make it very difficult to read the code. The function getTotalCashRegisterChange call within checkCashRegister can not work, because there is no function defined locally to the checkCashRegister function or in the global scope. That being said, there is a getTotalCashRegisterChange function inside getTotalRegisterStatus, but no other function can access it.

1 Like