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 trialIhosvany Diaz
2,946 PointsChallenge task 1 of 1 Modify the definition of the function named greeting to return a String and replace the println st
Hi everyone, I'm staking o this challenge and really don understand what do I have to do here is the function:
func greeting(person: String) {
println("Hello \(person)")
}
Thank
3 Answers
Chris Shaw
26,676 PointsHi Ihosvany,
The challenge is simply asking for you to remove the println
function and replace with with a return
statement then assign the return type as a String
, all of this was covered off in the previous video so I recommend you watch over it again just in case you missed anything the first time round.
func greeting(person: String) -> String {
return "Hello \(person)"
}
Ricardo Hill-Henry
38,442 PointsRemember, to make a function return a specific value you use the arrow following argument assignments. Next, get rid of println(). The challenge wants what println() was returning to be returned by the function as a obtainabe value.
func greeting(person: String) -> String {
return "Hello \(person)";
}
So now if I wanted, I can create a variable to hold the value returned by my greeting function:
var myFriendliness = greeting("Ihosvany Diaz");
myFriendliness //will return "Hello Ihosvany Diaz"
Ihosvany Diaz
2,946 PointsThank so much Chris Upjohn and cuckoo for your help this is the last challenge before complete the course