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

Shane Robbins
Shane Robbins
442 Points

Trouble with two strings in a function...

I'm trying to complete the "Hello Tom" challenge, however my second parameter is not being accepted... Any help would be great!

parameters.swift
func greeting(greet: String, person: String) {
    println(greet person)
}

1 Answer

Christopher Augg
Christopher Augg
21,223 Points

Shane,

Not a bad start. However, The instructions do state that you are only supposed to pass one parameter into the greeting function. Therefore, only (person : String) should be used. Another issue with your code is that you need to use String interpolation within the println statement. To do this, we surround our variable with parenthesis inside the String and place a \ in front of it.

Example:

    func honkHorn(animal : String) {
        println("I am honking my horn at a \(animal)")
    }

    honkHorn("Duck")

Please let me know if this helps.

Regards,

Chris