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 trialtytyty
4,974 PointsFunctions Extra credit challenge - please check
Write a function called fullName which takes two String parameters: firstName and lastName. It concatenates the two parameters and returns them as the fullName.
Is this good?
func fullName(firstName: String, lastName: String) -> String {
return firstName + lastName
}
3 Answers
William Li
Courses Plus Student 26,868 PointsLooks good to me. Although I'd like to add a space in between your first and last name to make output look nicer
func fullName(firstName: String, lastName: String) ->String {
return firstName + " " + lastName
}
One more thing, println("Performer's identity is = \(fullName (Iggy,Azalea))")
won't work, because fullName takes 2 strings arguments, and neither of what you pass in is String. You can do it like this instead:
let name = fullName("Iggy", "Azalea")
println("Performer's identity is = \(name)")
// => "Performer's identity is = Iggy Azalea"
Phil Hanson
764 PointsThis doesn't work for me, all kinds of weird things happening. I have:
func fullName(firstName: String, lastName: String) -> String {
return firstName + lastName
}
When I call this with fullName I get this weirdness.
fullName(firstName: String, lastName: String)
Except firstName: String are editable and only String for the second part is??? What is going on.
I should be able to have this:
func fullName(firstName: String, lastName: String) -> String {
return firstName + lastName
}
print(fullName("Phil","Hanson"))
But this doesn't work.
tytyty
4,974 PointsOh right! I have to declare a variable or constant first! AArrrghhhhh.
Thanks William
func fullName(firstName: String, lastName: String) -> String {
return firstName + lastName
}
let name = fullName("Iggy", "Azalea")
println("Performer's identity is = \(name)")
Would there ever be a situation where the let statement would be above the func?
Donnie Wang
1,842 PointsYour works. Alternative solution using string interpolation:
func fullName (firstName: String, lastName: String) -> String {
return "\(firstName) \(lastName)"
}
fullName("Iggy", "Azalea")
tytyty
4,974 Pointstytyty
4,974 PointsAlso if I wanted to print it out could I do something like this?
println("Performer's identity is = \(fullName (Iggy,Azalea))")