Please help me in this too am unable to find that what i am doing wrong

Tell us what’s happening:
Describe your issue in detail here.

   **Your code so far**

function checkCashRegister(price, cash, cid) {
 let change = cash*100 - price*100;
 let cidTotal = 0
 for (let elem of cid){
   cidTotal += elem[1]*100
 }
if (change > cidTotal){
} else if (change === cidTotal){
  return {status: "CLOSED", change: cid}
} else {
  let answer = []
  cid=cid.reverse()
  let moneyUnits = {"ONE HUNDRED": 10000, "TWENTY": 2000, "TEN": 1000, "FIVE": 500, "ONE": 100, "QUARTER": 25, "DIME":
  10, "NICKEL": 5, "PENNY": 1}
  for (let elem of cid){
  let holder = [elem[0], 0]
    elem[1]=elem[1]*100
    while (change >=  moneyUnits[elem[0]] &&elem[1] > 0){
      change -= moneyUnits[elem[0]]
     elem[1] -= moneyUnits[elem[0]]
     holder[1] += moneyUnits[elem[0]]/100
    }
    if (holder[1]>0){
      answer.push(holder)
    }
  }
  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]]));
   **Your browser information:**

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

Challenge: Cash Register

Link to the challenge:

Hello there.

Do you have a question?

If so, please edit your post to include it in the Tell us what’s happening section.

Learning to describe problems is an important part of learning how to code.

Also, the more information you give us, the more likely we are to be able to help.

Tell us what’s happening:
Describe your issue in detail here.

   **Your code so far**

function checkCashRegister(price, cash, cid) {
 let change = cash*100 - price*100;
 let cidTotal = 0
 for (let elem of cid){
   cidTotal += elem[1]*100
 }
if (change > cidTotal){
} else if (change === cidTotal){
  return {status: "CLOSED", change: cid}
} else {
  let answer = []
  cid=cid.reverse()
  let moneyUnits = {"ONE HUNDRED": 10000, "TWENTY": 2000, "TEN": 1000, "FIVE": 500, "ONE": 100, "QUARTER": 25, "DIME":
  10, "NICKEL": 5, "PENNY": 1}
  for (let elem of cid){
  let holder = [elem[0], 0]
    elem[1]=elem[1]*100
    while (change >=  moneyUnits[elem[0]] && elem[1] > 0){
      change -= moneyUnits[elem[0]]
     elem[1] -= moneyUnits[elem[0]]
     holder[1] += moneyUnits[elem[0]]/100
    }
    if (holder[1]>0){
      answer.push(holder)
    }
  }
  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]]));
   **Your browser information:**

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

Challenge: Cash Register

Link to the challenge:

Well, this is a challenge to complete the certification so nobody should be telling you what the problem is but we can try to help you figure it out.

The tests are telling you that you are failing one test in particular. It tells you what your function should be returning. Do you know how to figure out what you are actually returning?

1 Like

Tell us what’s happening:
Describe your issue in detail here.

its not running please help me
Your code so far


const currencyUnit = {
 "PENNY": 1,
 "NICKEL": 5,
 "DIME": 10,
 "QUARTER": 25,
 "ONE": 100,
 "FIVE": 500,
 "TEN": 1000,
 "TWENTY": 2000,
 "ONE HUNDRED": 10000
}
function checkCashRegister(price, cash, cid){

let changeSum = cash * 100 - price * 100;
let changeSumCheck = changeSum;
let change = [];
let status = '';

let cidSum = 0;
let filteredCid = cid.filter(elem => elem[1] !== 0).reverse();

filteredCid.forEach(elem => {
  let curr = elem[0];
  let currSum = currSum;
  let amount = 0;
  while (changeSum >= currencyUnit[curr] && currSum > 0) {
    amount += currencyUnit[curr];
    changeSum -= currencyUnit[curr];
    currSum -= currencyUnit[curr];
  }
  if (amount !== 0) {
    change.push([curr, amount / 100]);
  } 
});

if (changeSum > 0) {
  status = "INSUFFICIENT_FUNDS";
  change = [];
} else if (changeSum == 0 && changeSumCheck == cidSum) {
  status = "CLOSED";
  change = cid;
} else {
  status = "OPEN";
}
return { "status": status, "change": change };
}
console.log(checkCashRegister(19.5, 20, [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]));
  **Your browser information:**

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

Challenge: Cash Register

Link to the challenge:

**its not allowing me to run my code help!

  **Your code so far**

const currencyUnit = {
 "PENNY": 1,
 "NICKEL": 5,
 "DIME": 10,
 "QUARTER": 25,
 "ONE": 100,
 "FIVE": 500,
 "TEN": 1000,
 "TWENTY": 2000,
 "ONE HUNDRED": 10000
}
function checkCashRegister(price, cash, cid){

let changeSum = cash * 100 - price * 100;
let changeSumCheck = changeSum;
let change = [];
let status = '';

let cidSum = 0;
let filteredCid = cid.filter(elem => elem[1] !== 0).reverse();

filteredCid.forEach(elem => {
  let curr = elem[0];
  let currSum = currSum;
  let amount = 0;
  while (changeSum >= currencyUnit[curr] && currSum > 0) {
    amount += currencyUnit[curr];
    changeSum -= currencyUnit[curr];
    currSum -= currencyUnit[curr];
  }
  if (amount !== 0) {
    change.push([curr, amount / 100]);
  } 
});

if (changeSum > 0) {
 status = "INSUFFICIENT_FUNDS";
  change = []; 
} else if (changeSum == 0 && changeSumCheck == cidSum) {
  status = "CLOSED";
  change = cid;
} else {
  status = "OPEN";
}
return { "status": status, "change": change };
}
console.log(checkCashRegister(19.5, 20, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]));
  **Your browser information:**

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

Challenge: Cash Register

Link to the challenge:

Please do not create duplicate topics for the same challenge/project question(s). This duplicate topic has been unlisted.

Thank you.

ok but no one replied me for my questio

people asked you to clarify what issue you are having, you never answered to that

1 Like

no i cant i checked all my coding i dont get my mistaje

I would go back to the very first code you pasted here, it is very close to being correct, you are just missing one thing. Using that code you were only failing one test. Do you see the test output in the console underneath the code editor? It is telling you which test is failing. It is giving you the actual function call that is failing. It is telling you what your function should return using that function call. Do you think you can figure out what your function is actually returning for that function call? Debugging your code is a very important part of programming so you need to be able to do this.

Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**

function checkCashRegister(price, cash, cid) {
var change = cash - price;
let totalCash  = 0;
let cidReverse = [...cid].reverse();
let temp = [];
let cashValue = {
  "PENNY": 0.01,
  "NICKEL": 0.05,
  "DIME": 0.1,
  "QUARTER": 0.25,
  "ONE": 1,
  "FIVE": 5,
  "TEN": 10,
  "TWENTY": 20,
  "ONE HENDRED": 100
}
let changeDue = {
  status: '',
  change: []
}

cid.forEach(element => {
  totalCash += element[1];
});
totalCash = parseFloat(totalCash.toFixed(2))

function cashUnit(unit, index) {
  let unitTotal = cidReverse[index][1];
  let amount = Math.floor(change / cashValue[unit]) * cashValue[unit];
  if (unitTotal > 0) {
    if (unitTotal >= amount) {
    change -= amount;
    change = parseFloat(change.toFixed(2));
    return amount;
}
else {
  change -= unitTotal;
  change = parseFloat(change.toFixed(2));
  return unitTotal;
}
} 
else {
return 0;
}
}
function getChange() {
let changeOwed = cash - price;
for (let [index, value] of cidReverse.entries()) {
let changeGotten = cashUnit(value[0], index);
if (changeGotten > 0) {
  temp.push([value[0], changeGotten]);
}
if (change === 0) {break;}
}
if (totalCash < changeOwed || change !== 0) {
changeDue.status = "INSUFFICIENT_FUNDS";
}
else if (totalCash == changeOwed) {
changeDue.status = "CLOSED";
changeDue.change = [...cid];
}
else {
changeDue.status = "OPEN";
changeDue.change = [...temp];
}
}
getChange();
return changeDue;
}
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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36

Challenge: Cash Register

Link to the challenge:

They frown on creating duplicates here. Back in your original topic your first code was so close. As I suggested, you should go back to that code and figure out why that one test wasn’t passing.

2 Likes

Can you go back to that code so we can start there?

Have you tried this?

If you are having trouble debugging the issue, then ask follow up questions.

The forum wants to help you but you have to be specific on what you don’t understand about how to solve the problem. :grinning:

1 Like

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