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

Roderick Royce
Roderick Royce
1,236 Points

Function's Challenge 3 / 3 Call the function greeting and pass it the string "Tom".

func greeting(String) { let person = "XYZZY" println("Hello (person)") }

greeting(Tom)

// the above is what I thought would work but it is not the right String parameter style. What am I missing?

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

greeting("\(person)")

2 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi Roderick Royce,

You're code is very close to what it needs to be, you simply have some of it in the wrong spot :smile:

  1. Your function parameter is incorrect, a type of String on it's own is invalid. Instead it should be person: String

  2. You don't need to declare a constant called person within your greeting function as that is the argument we're going to pass into it

  3. When calling your greeting function we should be passing the string Tom into it as an argument.

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

greeting("Tom")

Happy coding!

Jhoan Arango
Jhoan Arango
14,575 Points

Hi Chris: Maybe you can help me answer my question ? It’s on the Forum!

Thanks

Roderick Royce
Roderick Royce
1,236 Points

Thank you Chris, you had the correct answer. I have only just begun and it is very difficult. Thank you for your support! C=

Chris Shaw
Chris Shaw
26,676 Points

You're welcome, you're not the only one in that boat so ask as many questions on the forum as you desire. We're always here to help. :thumbsup: