TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Requesting criticism of my Checkpoint 6 solution, please :)

Forums > 100 Days of SwiftUI

Dear team,

Requesting your constructive criticism of my solution to Checkpoint 6. I had abandoned the program a few months ago; I've returned to start from the beginning, and here is where I last left off. My knowledge is limited to Day 11.

Looking forward to your comments.

struct Vroom {
    let model: String
    let seats: Int
    private(set) var currentGear = 0

    func idle() {
        if currentGear == 0 {
            print("...")
            print("Why aren't we moving? Let's GO!")
        }
    }

    mutating func startCar() {
        currentGear = 1
        print("brum brum brum brum brum brum brum...")
    }

    mutating func gearUp() {
        if currentGear < 5 {
            currentGear += 1
            print("CLICK-PSST-CLANG! Vroooooom...")
        } else {
            print("RRRR!!! Gear down! You're breaking the car!")
        }
    }

    mutating func gearDown() {
        if currentGear > 0 {
            currentGear -= 1
            print("Clank-Psssh! brrr...")
        } else {
            print("Either gear up... or just get out and walk.")
        }
    }
}

var pintoBlue = Vroom(model: "Pinto", seats: 2)

pintoBlue.idle()
pintoBlue.startCar()
pintoBlue.gearUp()
pintoBlue.gearUp()
pintoBlue.gearUp()
pintoBlue.gearUp()
pintoBlue.gearUp()
pintoBlue.gearUp()
pintoBlue.gearDown()
pintoBlue.currentGear
pintoBlue.gearDown()
pintoBlue.gearDown()
pintoBlue.gearDown()
pintoBlue.gearDown()
pintoBlue.gearDown()
pintoBlue.idle()
pintoBlue.currentGear

2      

Hacking with Swift is sponsored by Blaze.

SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!

Reserve your spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.