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)
![evanpavan](https://uploads.teamtreehouse.com/production/profile-photos/10183142/micro_Evan_Pic_square.jpg)
evanpavan
5,025 PointsStruggling with the code challenge.
I'm having a tough time in the first exercise of the code challenge stubbing out the actual classes from the given tests.
Right now I'm getting a compilation error that my constructor can't have the same name as it's enclosing class.
public class Calculator
{
public double intialValue;
//constructor related to the Initialization test method
public double Calculator(double x)
{
intialValue = x;
}
//adding method related to the BasicAdd method
public double Add(double y)
{
//adding adds the value passed to the add method to the value the calculator was initialized with
double total;
total = y + initialValue;
return total;
}
}
using Xunit;
public class CalculatorTests
{
[Fact]
public void Initialization()
{
var expected = 1.1;
var target = new Calculator(1.1);
Assert.Equal(expected, target.Result, 1);
}
[Fact]
public void BasicAdd()
{
var target = new Calculator(1.1);
target.Add(2.2);
var expected = 3.3;
Assert.Equal(expected, target.Result, 1);
}
}
![Alan Brown](https://secure.gravatar.com/avatar/2337dd9cbb1aa38300dded5d8ffb60ca?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Alan Brown
20,524 PointsRemove the return type on your constructor.
1 Answer
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsI see three issues:
- "initialValue" is spelled "intialValue" in two places
- constructors should not have a return type (not even "void")
- the class to be tested must have a "Result" property or field
evanpavan
5,025 Pointsevanpavan
5,025 PointsSteven Parker I've recreated the question with my code. Thanks for the tips of this.