Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Dominick Chism
Dominick Chism
6,024 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 32,410 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
6,024 Points

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