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 trial

iOS Build a Vending Machine App in Swift Displaying Additional Views Controlling Custom Views

Why do we want the balance to reset to zero after an insufficient funds alert?

The actual balance still exists and is added to when we subsequently add funds. Shouldn't the balance keep the value present before the action that triggered the insufficient funds alert.

Chukwuebuka Willie-Nwobu
Chukwuebuka Willie-Nwobu
2,739 Points

We do this so that the user can start another purchase from scratch. Since they were unable to purchase an Item because they had insufficient funds, they can choose to buy another item, reduce the quantity or simply add more funds. :)

2 Answers

David Lin
David Lin
35,864 Points

It is a bug. Someone else wrote a fix for it here:

Small Glitch in the video's code. Here's how to fix.

Gavin Hobbs
Gavin Hobbs
5,205 Points

Hey Christopher Badger I'm confused about the same thing. I'm tempted to just leave that argument blank in the dismissAlert() function. I think that might have been a typo or something. Btw, Chukwuebuka Willie-Nwobu I think you might be confusing the Balance with the Total. The Total is how much is due for the current selection and the Balance is the amount of money the user is free to spend.

G'day!

-Gavin