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 trialMichael McKinley
1,476 PointsWhat is wrong with my code? I've been stuck for about 20 minutes
Please help!
func greeting(#person: String) -> String {
let person = "Jerry"
println("Hello \(person)")
}
greeting(person)
5 Answers
Daniel Sattler
4,867 Pointsi´m sorry, i didn´t see the hash Tag in your first post:
func greeting(#person: String) {
println("Hello \(person)")
}
greeting(person: "Jerry")
Michael McKinley
1,476 PointsThe prompt is:
Call the greeting function and pass it the String "Jerry"
Daniel Sattler
4,867 PointsTry it this way:
func greeting(person: String) {
println("Hello \(person)")
}
greeting("Jerry")
And here´s why:
You created a function and want to pass it an parameter in order to obtain your result. In this example Jerry.
By calling the function greeting(person) you are not passing the type of value that the function is expecting. In this case the function expects a String. The function tells you in it´s parameters, what it is expecting.
Another example:
func age(personsAge: Int){
println("I am \(personsAge) Years old.")
}
age(34)
in this case the function is expecting a parameter of type Int (Integer = whole number)
I hope this helps a little bit.
Michael McKinley
1,476 PointsThat didn't work either..
"Bummer! You need to define a func
named greeting
that takes one String
parameter named person
."
Michael McKinley
1,476 PointsThank you so much! That makes sense.
Ali ibrahim
557 PointsAli ibrahim
557 PointsThank you. It has helped me.