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

Do u guys have a right answer to these?

U know, it would be ideal to check on your ability as you go forward. There are no posted answers here. Imagine if this is Jeapordy and Alex never bothers to give the answers. "No thats not correct, lets go to the next question"

parameters.swift
func greeting(person) {
person = "Strong"
    println("Hello" \(person)")
}

1 Answer

Stone Preston
Stone Preston
42,016 Points

The code challenges are meant to be exactly that. A challenge. If the answers were posted it would remove the challenge aspect of the task and make them less fulfilling. They are meant to challenge you, and if you get stuck make a forum post and someone will usually clear up your confusion.

Task 1 states: Modify the function named greeting to accept a parameter. Name the parameter person which is of type String.

your current code has the parameter, but its missing the type. add the type in there by placing a : after the parameter name followed by the data type of the parameter

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

task 2 states Modify the println statement within the greeting function to use the variable person. For example, if you pass a person named "Tom" to the function then it should display: Hello Tom. (Hint: you must use string interpolation).

so you dont need to add another variable like you did person = "Strong". That is not necessary. just use the parameter person thats already defined in the function header. you also closed your string too early. the interpolation belongs inside both quotes:

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