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 trial

iOS

Riz Ainuddin
Riz Ainuddin
2,421 Points

Stuck 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. :smile:

4 Answers

Riz,

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")
Riz Ainuddin
Riz Ainuddin
2,421 Points

Thanks Aaron. Worked well. :thumbsup:

Sweet! Happy to help.

Riz,

For the first part you only need to add the parameter. person: String

func greeting(person: String) {

}
Riz Ainuddin
Riz Ainuddin
2,421 Points

Thanks Aaron. It's a winner. Nice.

func greeting(person person: String) {
    println("Hello \(person)")
}

Glad to help.

Bruno Azoulay
Bruno Azoulay
2,215 Points

this is great solution:

<p> 
func greeting(person: String)->String {
    return "Hello " + person
}

println(greeting("Tom"))
</p>
```
Riz Ainuddin
Riz Ainuddin
2,421 Points

Aaron,

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")