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!
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
Is it necessary to create the newAmount variable?
The same was accomplished if I replaced newAmount=mPezCount+pezAmount with mPezCount=+pezAmount;
Is that a valid way to go about it or will I run into problems eventually?
Seth Kroger56,412 Points
I have two answers for you that may seem contradictory:
Yes, that is a valid way to it. There is often more than one way to program something. Sometimes a problem is better suited to one solution then another, other times it's more which style you're comfortable with.
Yes, you will get into trouble later doing it that way. As I recall, you'll also be checking to see if you'd be overfilling the dispenser. It helps in that case to check the amount first before storing it.