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

brett phares
brett phares
1,314 Points

Function task challenge works in Xcode but not in treehouse editor window

The following works in Xcode but returns this error in treehouse editor, "Bummer! You shouldn't call println directly. It needs to be in the body of the function."

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

greeting()

Seems valid, println is inside the function (isn't it?), not sure how to troubleshoot.

3 Answers

Logan R
Logan R
22,989 Points

That is very weird. I tried your code and it worked just fine for me.

The only thing I can suggest is make sure you are not calling greeting() in the first task, only have the function being defined. Wait until task to to include greeting().

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

Hi, I'm having the same problem with this code. It works fine in Xcode, but is failing with the same error message as the original poster.

I'm running in Safari if that helps.

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

greeting()

Thanks, Pete

Logan R
Logan R
22,989 Points

Try it without the constant

func greeting() {
    println("Hello")
}
Peter O'Brien
Peter O'Brien
9,348 Points

Thanks, Logan. It worked with and without the content once I dropped the function call during step 1. I'd completely misread the question and tried to complete the whole challenge in one step. Normally, the challenge editor would just move onto the next step, but sorted now. Thanks.

Logan R
Logan R
22,989 Points

No problem.

The code editor did use to do that, but I bet they have changed that to stop people from just pasting in the code answers.