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

Mauricio Ariza
Mauricio Ariza
1,731 Points

Why don't I obtain the same result?

In this code according to the video: https://teamtreehouse.com/library/adding-a-method-solution the expected result is : ['programming', 'with', 'Treehouse','is','fun!']

but the result I have is: [ "P", "r", "o", "g", "r", "a", "m", "m", "i", "n", … ] note: I am using the same code that in the video.

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

thanks a lot!

2 Answers

Hi Mauricio Ariza,

Try adding a space between the string that you’re passing into the split method. It’ll look something like this: string.split(‘ ‘) instead of this: string.split(‘’).

Currently it doesn’t not look like there’s a space between the quotes, and so I think that instead of splitting at every space in the string Programming with Treehouse is fun!, it’s splitting after every character.

Mauricio Ariza
Mauricio Ariza
1,731 Points

Thanks a lot Brandon! it works adding it space :)