@wonderpig wonders about Checkpoint 6!
I've completed checkpoint 6 [...snip...]
What do you think about it?
This is a great solution. Many have submitted their Checkpoint 6 for critique. It's interesting to see how many ways this can be interpreted and solved.
You're on a journey. So bookmark this code and come and revisit it at day 50, 60, 70, etc. When you revisit this code, write down what YOU think of your Checkpoint 6 solution! I bet future you will have some great comments for past you!
For example, somewhere along the journey you'll hear about Magic Numbers. These are numbers you hard code into a solution just to get the code working, and make the compiler stop complaining. However, you'll come to recognize when you use magic numbers and you'll factor them out of your solutions.
But you may not even realize you're doing it in Checkpoint 6.
private(set) var maxGear = 6 // <-- here you set the maximum allowable gear.
private(set) var minGear = 0
mutating func gearUp(increment: Int) {
currentGear += increment
if currentGear > 6 { // <-- here you compare the currentGear to a magic number. This may not match your maxGear value!
currentGear = maxGear
print("You can't go to gear \(currentGear + increment) it'll break the car! You are now in gear \(maxGear)")
}
Also, as you progress, you may find yourself refactoring code. A lot.
// Past you wrote
if currentGear > 6 {
currentGear = maxGear
}
// Future you might write
currentGear > maxGear ? maxGear : currentGear // <-- Future you uses ternary operator instead
Nice job!
Keep Coding