Example Build a Cash Register does not comply to tests

Hi fCC,

The example from Build a Cash Register (Javascript) lets you push the button multiple times without resetting the Cash Register. Every time the cash amount is depreciated in the Cash Register. Only after refreshing the page is the Cash Register reinitiated.

I thought that was the way to code my own Cash Register. However, the result was that my programme complied with the demands, but did not pass the tests.
It took me quite a while to figure out that I had to reinitiate the programme every time the button was clicked, and not after refresh. And thus not to follow the example. Then the tests were ok.

My suggestion is that you update the example to reinitiate every time the button is clicked, so no one else gets this mix-up.

Best, Mac

the example app is programmatically checked against the tests, it passes them

the issue I think is a difference in behaviour when cid is changed by the tests. What does your app do when adding this code below yours? this is pretty much exactly what the tests do

console.log("\nTest #9");
price = 11.95;
document.querySelector("#cash").value = 11.95;
document.querySelector("#purchase-btn").click();
console.log("actual", document.querySelector("#change-due").innerText);
console.log("expected", "No change due - customer paid with exact cash");

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");

console.log("\nTest #14");
price = 19.5;
document.querySelector("#cash").value = 20;
cid = [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]];
document.querySelector("#purchase-btn").click();
console.log("actual", document.querySelector("#change-due").innerText);
console.log("expected", "Status: INSUFFICIENT_FUNDS");

console.log("\nTest #16");
price = 19.5;
document.querySelector("#cash").value = 20;
cid = [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 1], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]];
document.querySelector("#purchase-btn").click();
console.log("actual", document.querySelector("#change-due").innerText);
console.log("expected", "Status: INSUFFICIENT_FUNDS");

console.log("\nTest #18");
price = 19.5;
document.querySelector("#cash").value = 20;
cid = [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]];
document.querySelector("#purchase-btn").click();
console.log("actual", document.querySelector("#change-due").innerText);
console.log("expected", "Status: CLOSED PENNY: $0.5");

What you describe might mean there was some global dependency, calculated/performed just once, which was not being recalculated based on the current price and cid, when button was clicked.

When I copied the behaviour of the example app (continuously deduction, and no resetting of cid), explicitly thus setting an a global variable that remembered what happenend before, the tests failed.
Removing this global, and resetting all, did let me pass the tests. My app did not in functionality match thus the example.
My conclusion thus is, that the example is not reset conform test demands.

the example passes the tests, I assure you. You can have both continue reduction of values and also behaving properly when cid is updated by the tests

if you want help with your code, you need to share it.