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 trialJesse Gay
Full Stack JavaScript Techdegree Student 14,045 PointsExtending String with add func works in Xcode, but fails challenge. Why?
My solution works in Xcode but fails the challenge. Does anyone know why? The hint says "Make sure you're adding an add method that takes an Int and returns Int?" but I think my solution meets those criteria. The "best answer" for this challenge was similar, but used a guard statement instead. Thanks!
// Enter your code below
extension String {
func add(_ value: Int) -> Int? {
if let convertedNumber = Int(self) {
return (value + convertedNumber)
} else {
return nil
}
}
}
2 Answers
Magnus Hållberg
17,232 PointsIts just a small thing, you are omitting the external name in your method. The challenge doesn't tell you to do that so that gives you an error even though there is nothing wrong with your code. /M