# The cashier problem

Hi! Can someone help me with this problem? I don’t understand why the code doesn’t work…Thanks.

The Cashier Problem

Create a program that helps a cashier give adequate change to customers. The program should return the amount of notes and coins for the customer’s change.

Example: If the price is €3.75 and the paid amount is €50, then the client should receive €46.25 back in change.

• The expected output should be:

• 2 x €20 // 2 twenty euro notes

• 1 x €5 // 1 five euro note

• 1 x €1 // 1 euro

• 1 x €0.2 // 1 twenty cent coin

• 1 x €0.05 // 1 five cent coin

Example: Price: €4.50, Paid amount: €20, Change: 15.50

• Expected output:

• 1 x €10

• 1 x €5

• 1 x €0.5

• Notes

• Include outputs for exceptions e.g. price: €4, paid amount: €3.

*/

``````const cashier=(price, cash)=>{
let amountOfNotes;
let change = parseFloat((cash - price).toFixed(2));
console.log(`Price: \${price}`);
console.log(`Amount:\${cash}`);
console.log(`Change:\${change}`);

let current=[
["one cent coin",.01],
["two cents coin",.02],
["five cents coin",.05],
["ten cents coin",.10],
["twenty cents coin",.20],
["fifty cents coin",.50],
["one euro coin",1],
["two euros coin",2],
["five euros notes",5],
["ten euros notes",10],
["twenty euros notes",20],
["fifty euros notes",50],
["hundred euros notes",100],
["two hundred euros notes",200],
["five hundred euros notes",500]

]

for(let i=0;i<current.length;i++){
current.reverse();
console.log(current);
if(change>=current[i][1]){
amountOfNotes=Math.floor(change/current[i][1]);
console.log(amountOfNotes)
change=parseFloat((change%current[i][1]).toFixed(2));
console.log(`\${amountOfNotes} x \${current[i][1]} // \${amountOfNotes}x \${current[i][0]}`)
}
}

}
cashier(3.25,100);
``````

A post was merged into an existing topic: The cashier problem