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 trialJeff McDivitt
23,970 PointsYour task is to extend the String type and add a method that lets you add an integer value to the string. For example: "
Still getting error on this one when I am doing everything that is asked
// Enter your code below
extension String {
func add(number: Int) -> Int? {
guard let convertedNumber = Int(self) else{
return nil
}
return convertedNumber + number
}
}
1 Answer
Anthony Lafont
17,075 PointsHi jeff,
I think the only problem in your code is that you call the parameter in the add function "number", and in the exercice they want you to name it "value".
Here is my code:
extension String {
func add(value: Int) -> Int? {
guard let convertedNumber = Int(self) else { return nil }
return convertedNumber + value
}
}
Jeff McDivitt
23,970 PointsJeff McDivitt
23,970 PointsAhh!! I knew it was something little! Thanks Anthony!