Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMahdi Pedramrazi
2,505 PointsItem quantity update is misplaced.
shouldn't we decrease the item quantity after we are sure that the user has enough money to purchase ? this line of code can go at the end.
item.quantity -= quantity
3 Answers
Stefan Cimander
37,115 PointsYes absolutely, I think so, too. Both lines should be placed after the guard statements at the end of the function:
item.quantity -= quantity
inventory.updateValue(item, forKey: selection)
Zack Kitzmiller
2,182 PointsAgree 100%
Drew Carver
5,189 PointsI agree. I think these two lines:
item.quantity -= quantity
inventory.updateValue(item, forKey: selection)
should go in the if block, right after this statement:
amountDeposited -= totalPrice