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

Jennifer B
Jennifer B
2,672 Points

Function - println is in body of func, but getting error message

I am putting println within the curly braces of the func but the bummer message is telling me it needs to be in the body of the function. What am I doing wrong here?

greeting.swift
func greeting() {
var hello = "Hello"
println("\(hello)")
}

greeting()

3 Answers

Stone Preston
Stone Preston
42,016 Points

try removing the function call ( greeting() ) from the bottom. task 1 did not ask you to call the function

func greeting() {
var hello = "Hello"
println("\(hello)")
}

also, you could just print out the string literal "Hello" without assigning it to a var first if you wanted:

func greeting() {
println("Hello")
}
Jennifer B
Jennifer B
2,672 Points

thank you! I tried to non-var way first and it gave me the same error message about println needing to be in the body of the function. I bet my calling the function is the issue - thank you Stone!

Jennifer B
Jennifer B
2,672 Points

Yep that was it - by not calling the function, it went through fine. Thanks!

Stone Preston
Stone Preston
42,016 Points

cool glad you got it worked out