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 trialFrantyk Andrii
35,423 PointsAction and Func challange step2
What is wrong in my code public static Func<int, int> Square = (number) => number * number;
public static Action<int, Func<int, int>> DisplayResult = (result,function)=>Console.WriteLine(function(result));
using System;
namespace Treehouse.CodeChallenges
{
public class Program
{
public Func<int, int> Square = (number)=> number * number;
public Action<int, Func<int, int>> DisplayResult = (result,function)=>Console.WriteLine(function(result));
static void Main(string[] args)
{
}
}
}
3 Answers
Steven Parker
231,248 PointsThis challenge seems to have an overly-picky syntax checker.
While it's not required by C#, this challenge apparently requires a space in addition to the comma separating the arguments. You might want to report this as a bug to Support.
Also, your top line seems to have a stray static
qualifier added in, but the line shown in context does not.
Frantyk Andrii
35,423 PointsHelm me more pls!! Unit Testing in C# Frantyk Andrii Challenge Task 4 of 4
Implement the Subtract method so that the test passes. using System;
public class Calculator { public double Result;
public Calculator(double number)
{
Result = number;
}
public void Add(double number)
{
Result += number;
}
public void Substract(double number)
{
Result -= number;
}
}
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);
}
[Fact]
public void BasicSubtract()
{
var target = new Calculator(1.1);
target.Substract(0.2);
var expected = 0.9;
Assert.Equal(expected, target.Result, 2);
}
}
Frantyk Andrii
35,423 PointsError here
[Fact] public void BasicSubtract() { var target = new Calculator(1.1); target.Substract(0.2); var expected = 0.9; Assert.Equal(expected, target.Result, 2); }
Steven Parker
231,248 PointsYou should create a new question for a new topic, for several reasons:
- The "view challenge" button at the top is only correct for the first question.
- When you choose "best answer" it will be clear which question it answers.
- Others with similar problems might not be able to find the question and answer by title.
Also, be careful to quote your code correctly using the Markdown Cheatsheet.
Frantyk Andrii
35,423 PointsThanks, but i decided this question)
Steven Parker
231,248 PointsI'm not sure what you mean by "decided". It does not look like you have chosen a "best answer" yet.
I did find your new question and I also provided an answer there for you.