Build a Cash Register Project - Build a Cash Register

Prices variable iterate through cid array with map method And moving it part by part into shoppingCart class to do calculations. I also found the closest Denomination in addItem function and checked it in every price in "prices"variable to find the exact price.
When I move prices from global scope into addItem function, it won’t get updated and it stays the same no matter what your input value is.

no that update function just update changeDiv value based on cid array (this also needs prices variable that’s why I wrote it at the first of the function. when Price variable was declared in global scope I didn’t have to write it again in update function).

if you don’t undrestand from my explanation or my bad English grammer, just tell me I’ll try to explain better.

this line of code has to go.
You need to call update from within the purchase button click event.
not onload.

Since you’re saying that update is changing the #change-due element, then it cannot run only from the global scope.
You can run any code you like in the global scope if does not do anything important to either change-due or with the price or cid variables.
This update looks like it is doing something you need to make your code work, so it cannot be called in the global scope.

If you want something to happen you have to write code to make it happen.
If the prices is not getting updated, then why not?
Because there is nothing to update it.
Your update() function is only called on load, so start calling it whenever an event is triggered (whichever event makes sense , but usually the event that makes sense is the purchase button click because that’s the one the test runs)