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

JavaScript Practice Object Basics in JavaScript Practicing Object Basics Adding a Method Solution

3 Answers

It might help if you post some code for context. Without seeing that code, I would suggest you think about what "this" is referring to at any point. It's a subject with some depth, but the basic jargon is that it is determined by the invocation setting. I haven't looked at the code or the challenge yet, but I suspect "this" is being avoided because it would refer to something happening in a parent function or a prototype, rather than the instance "myString" represents.

Bader Alsabah
Bader Alsabah
4,738 Points

I think Barry above hit the spot with the answer - but just to perhaps add some clarity, as I have been following the video of this practice - the instructor does use the "this" keyword when referencing a property within the object declaration. In that context - "this" refers to the object and therefore using .dot notation on the object is valid. However, when she posts or console.logs the array - "this" wouldn't be referring to "myString" at that point or in that context. In fact if you try console.log with keyword "this" you will see that the value is undefined.

Steven Vallarsa
Steven Vallarsa
10,842 Points

I got

countWords() {return this.string.split(" ").length}

to work.