Exact Change Challenge

Exact Change Challenge
0

#1

Hey there. I’m struggling to understand this challenge. I know the function would return “Insufficient Funds” if (cash - price) is less than the sum of all currencies in the array, or return “Closed” if it is equal to, what I don’t understand is the third condition: “Otherwise return change in coin and bills”… I also know this is some sort of “return the change in coins and bills”, but despite that the currencies the array have aren’t “proportional” to their names. For example:

[“NICKEL”, 2.05], [“DIME”, 3.10], [“QUARTER”, 4.25], [“ONE”, 90.00], [“FIVE”, 55.00], [“TEN”, 20.00], [“TWENTY”, 60.00], [“ONE HUNDRED”, 100.00]

In this case, the “dime” currency shouldn’t be worth “3.10”, but 0.10, because that’s the original value of the currency, and so on with the other ones. Besides, in this passed parameters case:

(19.50, 20.00, [[“PENNY”, 1.01], [“NICKEL”, 2.05], [“DIME”, 3.10], [“QUARTER”, 4.25], [“ONE”, 90.00], [“FIVE”, 55.00], [“TEN”, 20.00], [“TWENTY”, 60.00], [“ONE HUNDRED”, 100.00]])

The expected returned answer according to FCC should be : [[“QUARTER”, 0.50]]

Why is that? First of all “Quarter” isn’t worth of 0.50 in the respective array, but 4.25. So please explain me this last condition about the challenge…


#2

You need to return 20.00 - 19.50 = 0.50. You can do that with two quarters (2 x 0.25): [[“QUARTER”, 0.50]]


#3

So why in the array example Quarter is worth of 4.25? Is that important when returning the solution?


#4

Quarter isn’t worth, but you have 4.25 / 0.25 = 9 quarters.


#5

I think 4.25 / 0.25 = 17, not 9. But now I get it. Thank you very much! :open_mouth: