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

Dominick Chism
Dominick Chism
8,857 Points

Confused on why we need to use the length property when returning the array.

What's the point of using the length property in this problem? I know that the challenge asks us for our method to return a number, but in the video, we never log that number into the console or anything, just the words of the array. As shown below, I didn't include the length property and could return the same result as in the video.

const myString = {
    string: "Programming with Treehouse is fun!",
  countWords: function() {
    const myArray = this.string.split(' ');
    return myArray;
  }
}

console.log(myString.string.split(' '));
Mark Sebeck
Mark Sebeck
Treehouse Moderator 37,905 Points

Great job figuring it out Dominick. I changed your comment to an answer and marked it the best one.

1 Answer

Dominick Chism
Dominick Chism
8,857 Points

Nevermind! Just realized we used it in the next challenge...