Problem passing The Cash Register

Tell us what’s happening:
Describe your issue in detail here.
Can’t pass the third Objective. Please where am i getting it wrong.

  **Your code so far**
function checkCashRegister(price, cash, cid) { 
let currency = {
  "ONE HUNDRED": 10000,
  "TWENTY DOLLARS": 2000,
  "TEN DOLLARS": 1000,
  "FIVE DOLLARS": 500,
  "DOLLAR": 100,
  "QUARTER": 25,
  "DIME": 10,
  "NICKEL": 5,
  "PENNY": 1
}
let change =cash *100 - price*100;
let cidTotal = 0
let result={
  status:"",
  change:[]
}
for(let i=0;i<cid.length;i++){
cidTotal += cid[i][1]*100
}
if(change > cidTotal){
result.status="INSUFFICIENT_FUNDS"
  return result;
}else if(change == cidTotal){
  result.status = "CLOSED"
  result.change=cid
  return result;
}else{
let answer = [];
cid = cid.reverse()
for(let item of cid){
  let box = [item[0], 0]
  item[1] = item[1]*100
  while(change >= currency[item[0]] && item[1] > 0){
    change -= currency[item[0]]
    item[1] -= currency[item[0]]
    box[1] += currency[item[0]] / 100
  }
  if(box[1]>0){
    answer.push(box)
  };
}
if(change > 0){
  return {status: "INSUFFICIENT_FUNDS", change: []};
}
return {status: "OPEN", change: answer}
}

}
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(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/102.0.0.0 Safari/537.36

Challenge: Cash Register

Link to the challenge:

Hmmm those properties look a little odd to me.

I multiplied them by 100 then later divided them to cuz of the decimal

image

1 Like

let answer = ;
function checkCashRegister(price, cash, cid) {
let currency = {
“PENNY”: 0.01,
“NICKEL”: 0.05,
“DIME”: 0.1,
“QUARTER”: 0.25,
“DOLLAR”: 1,
“FIVE DOLLARS”: 5,
“TEN DOLLARS”: 10,
“TWENTY DOLLARS”: 20,
“ONE HUNDRED”: 100,
}
let change =cash - price;
let cidTotal = 0;

for(let i=0;i<cid.length;i++){
cidTotal += cid[i][1]
}
if(change > cidTotal){
return {status: “INSUFFICIENT_FUNDS”, change: };
}else if(change == cidTotal){
return {status: “CLOSED”, change: cid};
}else{
cid = cid.reverse();
cid.forEach(item=>{
let box = [item[0], 0]
item[1] = item[1]*100
while(change >= currency[item[0]] && item[1] > 0){
change -= currency[item[0]]
item[1] -= currency[item[0]]
box[1] += currency[item[0]]
}
if(box[1]>0){
answer.push(box)
};
});

}
if(change > 0){
return {status: “INSUFFICIENT_FUNDS”, change: };
}
return {status: “OPEN”, change: answer}
}

//I made the corrections and decided to use a method to just check.

We are talking about property names, not the values. I highlighted the names you should use. Multiplying values by 100 to get rid of fractional part is not a bad idea.

Thanks man. I can’t believe that little thing held me. I appreciate

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