Build a Cash Register Project

Hi! I’m haveing some issues with this project can someone help me out?
I’ve finished writing the algorithm for the project and all the tests passed but left with two of them and that’s test 12 and test 19

As for test 12 it’s wierd to me I don’t know is there’s an error from you side or what.

It says

 When price is 3.26, the value in the #cash element is 100, cid is [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]], and the #purchase-btn element is clicked, the value in the #change-due element should be "Status: OPEN TWENTY: $60 TEN: $20 FIVE: $15 ONE: $1 QUARTER: $0.5 DIME: $0.2 PENNY: $0.04".

and when I run that I get this in the #change-due element:

Status: OPEN TWENTY: $60 TEN: $20 FIVE: $15 ONE: $1 QUARTER: $0.5 DIME: $0.2 PENNY: $0.04

which I don’t know the difference between

- freecodecamp: "Status: OPEN TWENTY: $60 TEN: $20 FIVE: $15 ONE: $1 QUARTER: $0.5 DIME: $0.2 PENNY: $0.04".
+ My code: Status: OPEN TWENTY: $60 TEN: $20 FIVE: $15 ONE: $1 QUARTER: $0.5 DIME: $0.2 PENNY: $0.04

and it’s not passing

And for the test 19
It says

When price is less than the value in the #cash element, total cash in drawer cid is equal to change due, and the #purchase-btn element is clicked, the value in the #change-due element should be "Status: CLOSED" with change due in coins and bills sorted in highest to lowest order.

which all my results obeyed this, here’s an example which I run test 18 and it passed

Status: CLOSED PENNY: $0.5

This says CLOSED and it’s followd by the change due and it’s also not passing

Please someone should help me out I’ve been working on this project more than a week, I don’t even know if I’ll get an instatnce response cus I need an instance response and I’ll appreciate if you do

The Javascript code snnipet of the project

please share your html too please

1 Like

When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.


See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (')

1 Like

Ok I’ll do that, thank you

Ok so this is the HTML code too

And if you’ll need the css to make things easy
The CSS code

And I’m sorry to any one who want to help but find it hard to read
This is my first time posting here.

the other thing that is important to share is the project link: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures-v8/build-a-cash-register-project/build-a-cash-register


Your code contains global variables that are changed each time the function is run. This means that after each function call completes, subsequent function calls start with the previous value. To fix this, make sure your function doesn’t change any global variables, and declare/assign variables within the function if they need to be changed.

Example:

var myGlobal = [1];
function returnGlobal(arg) {
  myGlobal.push(arg);
  return myGlobal;
} // unreliable - array gets longer each time the function is run

function returnLocal(arg) {
  var myLocal = [1];
  myLocal.push(arg);
  return myLocal;
} // reliable - always returns an array of length 2

you can see for your code that if you use the app once, it works fine:

console.log("\nTest #12");
price = 3.26;
document.querySelector('#cash').value = 100;
cid = [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]];
document.querySelector('#purchase-btn').click();
console.log("actual", document.querySelector('#change-due').innerText);
console.log('expected', 'Status: OPEN TWENTY: $60 TEN: $20 FIVE: $15 ONE: $1 QUARTER: $0.5 DIME: $0.2 PENNY: $0.04')

would print

Test #12
actual Status: OPEN TWENTY: $60 TEN: $20 FIVE: $15 ONE: $1 QUARTER: $0.5 DIME: $0.2 PENNY: $0.04
expected Status: OPEN TWENTY: $60 TEN: $20 FIVE: $15 ONE: $1 QUARTER: $0.5 DIME: $0.2 PENNY: $0.04

but using it twice in a row gives wrong result:

console.log("\nTest #11");
price = 19.5;
document.querySelector('#cash').value = 20;
cid = [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]];
document.querySelector('#purchase-btn').click();
console.log("actual", document.querySelector('#change-due').innerText);
console.log('expected', 'Status: OPEN QUARTER: $0.5')


console.log("\nTest #12");
price = 3.26;
document.querySelector('#cash').value = 100;
cid = [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]];
document.querySelector('#purchase-btn').click();
console.log("actual", document.querySelector('#change-due').innerText);
console.log('expected', 'Status: OPEN TWENTY: $60 TEN: $20 FIVE: $15 ONE: $1 QUARTER: $0.5 DIME: $0.2 PENNY: $0.04')

this prints:

Test #11
actual Status: OPEN QUARTER: $0.5
expected Status: OPEN QUARTER: $0.5

Test #12
actual Status: INSUFFICIENT_FUNDS
expected Status: OPEN TWENTY: $60 TEN: $20 FIVE: $15 ONE: $1 QUARTER: $0.5 DIME: $0.2 PENNY: $0.04
1 Like

Thank you @ILM , @tracy.chacon.00 and everyone
I’ve been able to complete it :grinning:

1 Like