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 Swift Functions and Optionals Parameters and Tuples Named Parameters

What is wrong with my code? I've been stuck for about 20 minutes

Please help!

named_parameters.swift
func greeting(#person: String) -> String {
    let person = "Jerry"
    println("Hello \(person)")
}
greeting(person)

5 Answers

Daniel Sattler
Daniel Sattler
4,867 Points

i´m sorry, i didn´t see the hash Tag in your first post:

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

Thank you. It has helped me.

The prompt is:

Call the greeting function and pass it the String "Jerry"

Daniel Sattler
Daniel Sattler
4,867 Points

Try it this way:

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

greeting("Jerry")

And here´s why:

You created a function and want to pass it an parameter in order to obtain your result. In this example Jerry.

By calling the function greeting(person) you are not passing the type of value that the function is expecting. In this case the function expects a String. The function tells you in it´s parameters, what it is expecting.

Another example:

func age(personsAge: Int){
println("I am \(personsAge) Years old.")
}

age(34)

in this case the function is expecting a parameter of type Int (Integer = whole number)

I hope this helps a little bit.

That didn't work either..

"Bummer! You need to define a func named greeting that takes one String parameter named person."

Thank you so much! That makes sense.