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!

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 trial


Mehran Amini Tehrani
Mehran Amini Tehrani
1,523 Points

iOS functions

Is the answer for question below right?

// Write a function called fullName which takes two String parameters: firstName and lastName. It concatenates the two parameters and returns them as the fullName.

func fullName (firstName: String, lastName: String) ->String { return("firstName", "lastName")


fullName("Mehran", "Amini")

2 Answers

Martin Wildfeuer
Martin Wildfeuer
Courses Plus Student 11,071 Points
func fullName (firstName: String, lastName: String) -> String {
   return("firstName", "lastName")

fullName("Mehran", "Amini")

Although your function is expected to return only a single string -> String, you are returning two strings. Thus, the return type you have declared and what you are actually returning does not match. Moreover, you are not returning the variables, but plain strings "firstName" and "lastName". This is how it would work:

func fullName (firstName: String, lastName: String) -> String {

   // Version 1: string interpolation
   let name = "\(firstName) \(lastName)" 

   // --- alternatively ---

   // Version 2: + operator
   let name = firstName + " " + lastName

   // Now return the constant name, containing a string
   return name

// Now we are calling the function
let name = fullName("Mehran", "Amini") // name is now "Mehran Amini"

Hope that helps :)