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

Swift Functions Challenge Task 1 of 2 (greeting.swift) Don't understand my problem.

Challenge is to declare a function called greeting and use println that outputs "Hello". I write:
func greeting() { println("Hello") } greeting()

I get this: Bummer! You shouldn't call println directly. It needs to be in the body of the function.

What am I doing wrong? To me (a definite newbie) it looks just like what the lesson did. Should I do something like, let message = "Hello" then println(message) ????

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

1 Answer

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

You just have to create the function with println statement in the body of it. Don't call the function yet -> w8 4 step 2

Thank you Nejc. I guess I'm getting ahead of myself.

Welcome. Don't worry I'm the same from time to time. Make sure you read the challange 2 times and always check for typos.

And you'll be up and running full speed.