Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJohn Scully
1,018 PointsExtra, extra credit?
I put this together as a way of calling multiple functions. What I'm interested in is any feedback to make the code more streamlined as it seems like I'm using a lot of lines:
let salutation = "Hello"
func fullName(firstName: String, lastName: String) -> String {
return ("\(firstName) \(lastName)")
}
func personalGreeting(fullName: String) ->String {
return ("\(salutation) \(fullName)")
}
personalGreeting(fullName("Iggy", "Azalea"))
2 Answers
Caleb Kleveter
Treehouse Moderator 37,862 PointsI think a closure would make fewer lines:
func personalGreeting(salutation: String, fullName: (firstName: String, lastName: String) -> (String)) ->String {
return ("\(salutation) \(fullName)")
}
personalGreeting(salutation: "Hello", firstName:"Iggy", lastName"Azalea")
See if that works.
pjc90
10,267 PointsI would have done it like this..
func personalGreeting(firstName: String, lastName: String) -> String {
return ("Hello \(firstName) \(lastName)")
}
personalGreeting("Iggy", "Azalea")
John Scully
1,018 Pointsyeah i wanted to call multiple functions rather than just rely string interpolation. I figure it'll be important later. thanks though!
John Scully
1,018 PointsJohn Scully
1,018 Pointshmmm I think I can see what you're getting at here but I can't get it to execute. The function's themselves seem to run fine but I haven't quite understood how to correctly call the functions.
I've tried the following: