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 trialJessie Doherty
7,571 Pointsobject literal question
Not so sure why my code for countWords() method doesn't work.
const myString = {
string: "Programming with Treehouse is fun!"
countWords() {
return myString.string.split(' ');
}
}
1 Answer
Steven Parker
231,248 PointsIt looks like there are 3 issues:
- the comma to separate the properties is missing
- internal references to the object should use the keyword "this" instead of the object name
- the function is returning an array of words instead of the number of words
The next video will show the teacher's solution with a full explanation.
Jessie Doherty
7,571 PointsJessie Doherty
7,571 PointsThank you so much Steven for answering my question. I didn't realize that right after this challenge, Treehouse offered a solution. But your help is very much appreciated!!!