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 trialJennifer B
2,672 PointsFunction - 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?
func greeting() {
var hello = "Hello"
println("\(hello)")
}
greeting()
3 Answers
Stone Preston
42,016 Pointstry 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
2,672 Pointsthank 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
2,672 PointsYep that was it - by not calling the function, it went through fine. Thanks!
Stone Preston
42,016 Pointscool glad you got it worked out