In the challenge of Cash Register Project, there’ s a condition that states like this:
When price is 19.5, the value in the #cash element is 20, cid is [[“PENNY”, 0.01], [“NICKEL”, 0], [“DIME”, 0], [“QUARTER”, 0], [“ONE”, 1], [“FIVE”, 0], [“TEN”, 0], [“TWENTY”, 0], [“ONE HUNDRED”, 0]], and the #purchase-btn element is clicked, the value in the #change-due element should be Status: INSUFFICIENT_FUNDS.
And the condition for INSUFFICIENT_FUNDS looks like this
if (cashInDrawer < changeDue) {
changeDueDiv.textContent = ‘Status: INSUFFICIENT_FUNDS’;
}
With our case, I can see that “cashInDrawer” will be (1 + 0.01) = 1.01, and the changeDue will be (20 - 19.5) = 0.5;
With that, Why would it result in insufficient balance when the cashInDrawer is greater than the changeDue !!
I guess the Status would be OPEN instead; because according to the passing conditions, the code will never pass.
1.01 is of course higher than 0.5. However you cannot take bill that has denomination of 1 and torn it apart to get two 0.5 bills . With money that is in the drawer it’s impossible to give out 0.5 change.
I’ve edited your code for readability. 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.