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 Syntax and Parameters

Sam Blaha
Sam Blaha
15,146 Points

Why is it forcing me to use XYZZY?

I know what to do to fix this. Change let name = "XYZZY" but why is it forcing me to use XYZZY?? It says no where in those instructions to use XYZZY.

parameters.swift
func greeting(person: String) {
    let name = "Tom"
    println("Hello \(name)")
}

2 Answers

Hi Sam,

The issue with your code isn't the use of which name you've chosen - it is the creation of a constant inside the method. That's not required.

I don't know what error you're receiving but it may be misleading.

You've hard-coded "Tom" into the method by defining a constant. You're then using string interpolation to output "Hello Tom". So you've done the hard bit of this challenge! However, if you remember the first step of the challenge was to modify the method so that it took a string as a parameter? That's the string you should be interpolating into the println method. The method does not have a hard-coded name.

func greeting(person: String) {
    println("Hello \(person)")
}

greeting("Tom")  // call the function using "Tom"

I hope that makes sense.

Steve.

Sam Blaha
Sam Blaha
15,146 Points

I got it. Thanks! But the weird thing is when I hard coded "Tom" it wouldn't work but hard coding "XYZZY" works... Is there something about XYZZY that makes it unique?