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

Can't get passed

I am having a problem with this task I have added the following to the println statement but it's not accepting it

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

help?!

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

2 Answers

Shawn Flanigan
PLUS
Shawn Flanigan
Courses Plus Student 15,815 Points

Anthony, I'm guessing you're stuck on challenge task 2, right? It looks like you're trying to call the function (greeting) from within the function that you're defining, which won't work. You can't define something and use that thing within the definition. It would be like saying "To Jabberwock the apple, start by jabberwocking it."

Here, they're just asking you to tell the function what to do with the parameter we're passing it (person). In this case, we want to add it to our "Hello" message. To do this in Swift, you'll simply use the + symbol, followed by your variable. Should look something like this:

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

Hope this makes sense!

thanks for that...school boy error!