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 Functions Syntax and Parameters

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

What am I doing wrong?

parameters.swift
func greeting(#person: String) {
    println("Hello \(person)")
}

greeting( person: "Jerry")

I've learned that with these challenges you need to read it carefully. After the video lesson, I would read it and type out the whole lesson and wonder what I did wrong. Most of the time it was because I was providing too much information, which seems to be your case as well. Look at the challenges, if it has 1 of 3 or something like that, don't overthink your coding. Good luck!

1 Answer

Chris Shaw
Chris Shaw
26,676 Points

Hi easton breinholt,

You're code is almost correct, however you have a couple of extras/differences that the challenge isn't expecting.

  1. You've defined person as a named parameter which it doesn't need to be, in this case you can omit the hash/pound # and remove person: from your greeting function call

  2. You have passed Jerry as the string to greeting, instead this should be Tom as per the task.

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

greeting("Tom")

Happy coding!

Thank you.