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 trialRiz Ainuddin
2,421 PointsStuck on Stage 2 Parameters and Tuples : Task 1
The task is
Challenge Task 1 of 2
Modify the existing greeting function to have an external parameter named person.
I entered this code from what I understand on the introduction of Parameters and Tuples. In Xcode this works well.
func greeting(#person: String) -> String {
return ("Hello \(person)")
}
greeting(person: "Riz")
Got this error message.
Bummer! You need to define a func
named greeting
that takes one String
parameter named person
.
I don't understand what is required here. Appreciate the pointers here.
4 Answers
agreatdaytocode
24,757 PointsRiz,
This code snippet worked for me:
It looks like you have language then greeting, not greeting, language in the func paramaters.
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}
var result = greeting("Tom")
agreatdaytocode
24,757 PointsRiz,
For the first part you only need to add the parameter. person: String
func greeting(person: String) {
}
Riz Ainuddin
2,421 PointsThanks Aaron. It's a winner. Nice.
func greeting(person person: String) {
println("Hello \(person)")
}
agreatdaytocode
24,757 PointsGlad to help.
Bruno Azoulay
2,215 Pointsthis is great solution:
<p>
func greeting(person: String)->String {
return "Hello " + person
}
println(greeting("Tom"))
</p>
```
Riz Ainuddin
2,421 PointsAaron,
On the second task. I still don't get it. "Bummer! Your result
variable has the wrong value in it. Check the task instructions again."
Checked the other forum thread. It seems I got it right but it's not af. I passed the greeting func to the variable results as instructed. Bit lost now.
func greeting(person: String) -> (language: String, greeting: String) {
let language = "English"
let greeting = "Hello \(person)"
return (language, greeting)
}
var result = greeting("Tom")
Riz Ainuddin
2,421 PointsRiz Ainuddin
2,421 PointsThanks Aaron. Worked well.
agreatdaytocode
24,757 Pointsagreatdaytocode
24,757 PointsSweet! Happy to help.