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
Stuart Keenan
3,131 PointsOverthinking refactoring challenge
This is not the first time I had this problem, but I over thought the refactoring challenge big time. I knew what needed to be done (create a way for someone to enter an item and not a quantity and to have the quantity default to 1 when done so). After learning how to use .length on strings in order to determine if anything was entered at all I tried to find the equivalent for ints. I understand the solution after coming to this board, but I would like to know if there is another way to solve this challenge. I came across the Optional class and nulls in my search. Is there a way using one method signature to set the int quantity as an optional field and when a value is not entered it defaults to 1, and if a value is entered it replaces the default value of 1 or adds to it (accounting for the existing 1 of course)?