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

Peter O'Brien
Peter O'Brien
9,348 Points

I can't get the code to run. I get an error message stating I can't run Println directly with or without constant use.

These are the functions I've tried:

func greeting() {
  let hi = "Hello"
    println(hi)
}
greeting()
func greeting() {
    println("Hello")
}
greeting()

Its worth noting that both run fine in Xcode. I am using the Safari browser on Mac.

3 Answers

If you're on the first question, they aren't asking you to call greeting() yet, so just delete that for now. This is all you need for the first task:

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

Are you trying to call greeting() in Task 1? You second function is correct, but the Challenge throws that error if you try to call greeting() outside of Task 2.

Peter O'Brien
Peter O'Brien
9,348 Points

Thanks, Bryan. Clearly trying run while the challenge was asking me to walk :-) I don't know how I missed that in the question.

Best, Pete