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 Encapsulation with Properties Property Initial Values

Not understanding how 'factor' works

In the last part of the video we create a field named 'DecreasedHealth' and give it an argument of 'int factor', then we create another field 'Health -= factor' To me, this doesn't make much sense, how does this math even work if factor is never assigned an actual number? Can someone explain this to me?

Yeah I think the confusion arises from calling it 'factor', I'm not sure why Jeremy picked that. I just called it 'amount' in the code I wrote.

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! It's not assigned a number currently because we want to pass in the factor when we call it. I know this is based on a Tower game, but let's assume that this is an RPG instead. We have an Invader that is level 1, but our character is level 10 and has an amazing sword. If we were to then to make an instance of Invader called "tinyInvader" we could call the DecreaseHealth method on it and send in a factor. But because we have the really awesome sword, we can send in a factor of 10. So something like tinyInvader.DecreaseHealth(10);. At that point we will take the invader and decrease its health by 10 because we're sending in the factor. However, if our sword breaks or gets damaged our factor should go down. If that happens, we'd expect to see something like tinyInvader.DecreaseHealth(2);.

Hope that clarifies things! :sparkles:

Ohhhhhh I completely understand, it's just the circumstances that make the outcomes the way they are. Thank you!