Silver Challenge

The emptyGas() 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()’s implementation to ensure that gasLevel is not decremented to be a negative value.

Get Swift Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.