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 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")
}
lordcozycat
lordcozycat
11,940 Points

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