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 Function Return Types

Nick Gressle
Nick Gressle
736 Points

Trouble with Functions challenge

I am working on the Functions section of the Swift course and I cannot get the test challenge to compile. I put my code into an XCODE playground and it works there. I am not sure what I am doing wrong.

My code below.

// Playground - noun: a place where people can play

import UIKit

func greeting
    (personName: String) -> String {
    let greeting = "Hello, " + personName + "!"
    return greeting
}
println (greeting("Tom"))

1 Answer

Andrew Shook
Andrew Shook
31,709 Points

So that problem is the comma and the exclamation point. The code challenge is not checking your code so much as it is checking the output of your code. Given the name, Tom, you code should output "Hello Tom". Instead, your code is outputting "Hello, Tom!". If you remove the comma and the exclamation point then your code should pass the challenge.

// Playground - noun: a place where people can play

import UIKit

func greeting(personName: String) -> String {
    let greeting = "Hello " + personName 
    return greeting
}
println (greeting("Tom"))
Nick Gressle
Nick Gressle
736 Points

Thank you so much!! I was having a major brain lock on this one.

Andrew Shook
Andrew Shook
31,709 Points

No worries, it happens. At my office when we run into problems like this, problems that shouldn't exist but do, we call out "Sanity Check" and someone else comes over to look at the code. Most of the time a fresh pair of eyes can spot the problem in seconds.