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 trialTrevor Justice
1,965 Pointsstruct Coding Challenge Help
Hello,
I'm new to programming and trying to complete this coding challenge using structs and methods. I'm working in my Xcode Playground, and have tried every variation of things I could think of to put inside fullName, yet I always get an error by return which reads ¨Unexpected non-void return value in void function¨. If anyone could explain to me why the code isn't working, and suggest a way to fix it, I would greatly appreciate it.
Thank you! Trevor
struct Person {
let firstName: String
let lastName: String
func fullName(first: String, last: String) {
let name = first + last
return name
}
}
1 Answer
Michael Ayoub
7,689 PointsYou are attempting to return a string from a function that is expected to return Void(which means nothing). The function must be:
func fullName(first: String, last: String) -> String
Trevor Justice
1,965 PointsTrevor Justice
1,965 PointsThank you, I understand now!