Functions: Bronze Challenge

Nested guard statements…works.

func greetByMiddleName(fromFullName name: 
(first: String, middle: String?, last: String)) {
    
    guard let middleName = name.middle, middleName.count > 10 else {
        guard let middleName = name.middle, middleName.count <= 10 else {
            print("Hey there!")
            return
        }
        print("Hey \(name.first) \(middleName) \(name.last)!")
        return
    }
    
    print("Hey \(name.first) \(middleName.prefix(1)). \(name.last)!")
    
}

//Hey Alice R. Chaz!
greetByMiddleName(fromFullName: ("Alice", "Rumpelstiltskin" ,"Chaz"))

//Hey Alice Rump Chaz!
greetByMiddleName(fromFullName: ("Alice", "Rump" ,"Chaz"))

//Hey there!
greetByMiddleName(fromFullName: ("Alice", nil ,"Chaz"))
1 Like