Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift Functions and Optionals Functions Syntax and Parameters

Curtis Curry
Curtis Curry
717 Points

I need a hand...

I'm really struggling with step 3 of 3 of this challenge. Any breadcrumbs that you guys can throw me would be much appreciated as I am totally lost!

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

2 Answers

The challenge never asks you to create a new constant named 'greeting'. The solution should look like this after all 3 tasks of the challenge:

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

The goal of this example is to create function because it makes life easier. For example : you could have just create variables and assign to them random values and then use println() method to display back to the user (see code below )

            var person : String = " John "
             println("Hello \(person) ")

However this method is not really efficient . Lets say you had to input 50+ names it will take you sometime. Therefore you could create a function that takes one parameter and return or display using the println() whatever you assign to it , and this will save the day !!! :)

                  / / create the function using keyword func 
                func greeting(person: String) {
                  println("Hello \(person)")
               } 

         greeting("Tom")     // you call back  the function 

Hope that helps ...