O'Reilly logo

Swift Programming: The Big Nerd Ranch Guide by John Gallagher, Matthew Mathias

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Silver Challenge

The emptyGas(by:) method has some bugs. For example, if the current gasLevel is less than the amount to remove, then the new value for this property will be negative. A negative value does not make sense and will actually stop the program from running (recall the precondition() in gasLevel’s property observer). Revise emptyGas(by:)’s implementation to ensure that gasLevel is not decremented to be a negative value.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required