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

Salman Elmi
Salman Elmi
3,528 Points

I need help modifying the (println) statement within the (greeting) function to use the variable (person).

Can someone explain to me what I'm doing wrong?

Thanks!

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

greeting("XYZZY")

2 Answers

Stone Preston
Stone Preston
42,016 Points

the person variable is already defined in the parameter (person: String).

parameters are things that get passed to the function when it is called. you can use parameters in the body of functions you write.

you dont need to add a person var in the function body, just use the parameter:

func greeting(person: String) {
    //the value of whatever string that gets passed to the function will be inserted after Hello
    println("Hello \(person)")
}

also dont call the function until you get to task 3. if you put the function call in task 2 it might not pass you since its not expecting that to be there yet

Salman Elmi
Salman Elmi
3,528 Points

Thank you for your swift answer (no pun intended)! Greatly appreciated!

Stone Preston
Stone Preston
42,016 Points

no problem glad it helped you out