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

C# C# Objects Methods Method Overloading

Tojo Alex
PLUS
Tojo Alex
Courses Plus Student 13,331 Points

I think I'm almost there

I think I almost did the challenge though I have this error: Frog.cs(19,16): error CS1520: Class, struct, or interface method must have a return type Compilation failed: 1 error(s), 0 warnings

Frog.cs
namespace Treehouse.CodeChallenges
{
    class Frog
    {
        public readonly int TongueLength;

        public Frog(int tongueLength)
        {
            TongueLength = tongueLength;
        }

        public bool EatFly(int distanceToFly)
        {
            return TongueLength >= distanceToFly;
        }

        public readonly int ReactionTime;

        public reactionTime(int reactionTime)
        {


        }
   }
}
Mathew Tran
Mathew Tran
Courses Plus Student 10,205 Points

Your reactionTime function might need looking at. The compiler is telling you that the method is expecting a return type.

Consider how you worked on the EatFly function.

public bool EatFly(int distanceToFly)
        {
            return TongueLength >= distanceToFly;
        }

Note how the return type is bool, and you returned a bool.

Good luck!

Matt

4 Answers

Tojo Alex
PLUS
Tojo Alex
Courses Plus Student 13,331 Points

I understand that though now I don't know what the return type is

Mathew Tran
PLUS
Mathew Tran
Courses Plus Student 10,205 Points

Ah, just checked the challenge, sorry about that.

So the task is asking you to modify the constructor of the class. The reactionTime method should not exist

public Frog(int tongueLength)
        {
            TongueLength = tongueLength;
        }

You need to add a reactionTime parameter, and also assign it like they have done for TongueLength.

Matt

Tojo Alex
PLUS
Tojo Alex
Courses Plus Student 13,331 Points

ok now it makes more sense . could you just show the code of the same challenge because it tells me that one of my braces are in the wrong place or that there are missing semi colons. I f you show your code it would be easier to me to refer and so I can figure out what I'm doing wrong so I can improve, instead of you telling me directly.

Mathew Tran
Mathew Tran
Courses Plus Student 10,205 Points

Err, not to be stubborn, but I think it would be good for you to write in the code yourself instead of me giving you the answer.

I've provided comments where you need to update your code to make this challenge pass.

namespace Treehouse.CodeChallenges
{
    class Frog
    {
        public readonly int TongueLength;
        // Add public readonly int ReactionTime variable

        public Frog(int tongueLength) // Add Parameter, int reactionTime
        {
            TongueLength = tongueLength;
             // Set ReactionTime variable like it is done for tongueLength, but with reactionTime
        }

        public bool EatFly(int distanceToFly)
        {
            return TongueLength >= distanceToFly;
        }

        public readonly int ReactionTime;

        public reactionTime(int reactionTime) // Remove this function
        {


        }
   }
}

Hope this helps.

Matt

Tojo Alex
PLUS
Tojo Alex
Courses Plus Student 13,331 Points

don't worry I'm not copying I have already done the code is just I think my eyesight is a bit off today so nothing to worry I don't like to cheat its only the braces and semicolon. note that I'm part 2 of the stage thanks