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 Creating a Function

i have a problem with functions, please help

this is my code, println ("Hello") func (greeting)

please help :(

greeting.swift
println (" Hello" )
func \(greeting)

1 Answer

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 Points

A few things:

  • reverse the order of the two lines - so you start with the keyword func declaring the function
  • you don't need a backslash
  • greeting shouldn't be inside the parentheses, the parentheses go after it like this: greeting()
  • then you need a set of curly braces { }
  • inside those curley braces is where you put the things that the function does: in this case printing out "Hello"
  • there should be no space between println and the parentheses: println("Hello")
  • make sure there are no extra spaces inside the parentheses or inside the quotes. Both the Swift language and this particular challenge are picky.

So the whole code would look like this:

func greeting() {
    println("Hello")
}