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 trialJason Cornwall
9,645 PointsString Interpolation?
I am doing the first code challenge for the Fun Facts app to test my understanding of object oriented programming. I believe I have all of the logic correct but for some reason it's saying that I'm not returning the right sting. Im not sure why. The challenge says for example, given a title: ''iOS Development", author: "Apple", and a tag named "swift", the description would read "iOSDevelopment by Apple. Filed under swift". I hope someone can see my error.
2 Answers
Luke Glazebrook
13,564 PointsHi Jason!
Do you mind pasting your code here into the forums so we can see what you are having problems with?
It should look something like this:
print("\(title) by \(author). Filed under \(tag)")
I'm not sure if I have used the proper variable names there but the basic outline should work fine.
-Luke
Jason Cornwall
9,645 Pointsstruct Tag { let name: String init(name: String) { self.name = name } }
struct Post { let title: String let author: String let tag: Tag
init(title: String, author: String, tag: Tag) {
self.title = title
self.author = author
self.tag = tag
}
func description () -> String {
return "\(self.title) by \(self.author). Filed under \(self.tag)"
}
}
let firstPost = Post(title: "iOS Development", author: "Apple", tag: Tag(name: "swift")) let postDescription = firstPost.description() print(postDescription)