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 trialJaron Trotter
11,472 PointsHow do I write this code
I'm trying to write a simple function code. It's saying I can't call on the println directly. It needs to be inside the body.
func greeting() {
let right = "Hello"
println("right")
}
greeting ()
2 Answers
Tobias Helmrich
31,603 PointsHey there,
I think you're overthinking it a bit by assigning "Hello" to a constant which you don't really need to. However if you do, you have to remove the quotes around "right" in your println
function because right now you're printing out the String "right" instead of the right
constant.
If you print it out without an extra constant it should look like this:
func greeting() {
println("Hello")
}
greeting()
Also note that in Swift 2 println
became deprecated and that you have to use print
now.
I hope that helps! :)
Jaron Trotter
11,472 PointsThank you for your help!