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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Arthur Rubio](https://secure.gravatar.com/avatar/b0d63be09549159e1defd537f84c4061?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Arthur Rubio
4,657 PointsI'm having difficulty with the challenge: Write a function named addTwo, task 1 of 2
I am having trouble with the following question: Write a function named addTwo that accepts an Int, adds the value 2 to it and returns the resulting integer. Note: This task doesn't require that you call the function yet.
I receive the error: "Make sure your function is named addTwo, accepts an Int, and returns an Int.". Here is the code I am using:
// Enter your code below
func addTwo(a: Int, b: Int) -> Int {
return a + b
}
4 Answers
![Arthur Rubio](https://secure.gravatar.com/avatar/b0d63be09549159e1defd537f84c4061?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Arthur Rubio
4,657 PointsNever mind, it just took me a 2nd(or 8th) try.
func addTwo(a: Int) -> Int {
return a + 2
}
Here is the rest of it for task 2 of 2 if anyone needs it:
/*
let addition = addTwo
let result = addition(5)
*/
![Jennifer Nordell](https://uploads.teamtreehouse.com/production/profile-photos/5432702/micro_jen-square.jpg)
Jennifer Nordell
Treehouse TeacherWell the good news is that your code is functional. But challenges are super picky and you've written code that adds two numbers together. Which isn't a bad thing! But what the challenge wants is to be able to pass in any integer and the function will add two to it. So if we were to pass in a 9 ... it'll return an 11. If we pass in a 40... it'll return a 42. So give it another try with a new understanding of the instructions
![Eric Hodgins](https://uploads.teamtreehouse.com/production/profile-photos/720922/micro_shadow.jpg)
Eric Hodgins
29,207 PointsHi Arthur, you should just pass in 1 Int value. Not two. With that Int value add 2 to it.
Something like: return a + 2
![Aananya Vyas](https://uploads.teamtreehouse.com/production/profile-photos/7550172/micro_IMG_6129.jpg)
Aananya Vyas
20,157 Pointswe would need an external argument 'to' to be added too for the challenge to pass as the challenges tend to be really picky so ...
func addTwo(to a: Int) -> Int {
return a + 2
}
something like this... :)
Eric Hodgins
29,207 PointsEric Hodgins
29,207 Pointsoh nice!
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherWay to go on figuring it out!![:dizzy: :dizzy:](https://image-proxy-cdn.teamtreehouse.com/c2cf9bffe9990560f0066a99586597f4131a1a67/68747470733a2f2f7374617469632e7465616d74726565686f7573652e636f6d2f696d616765732f656d6f6a692f756e69636f64652f31663461622e706e67)