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

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 ...