JavaScript Practice Object Basics in JavaScript Practicing Object Basics Practice Adding a Method to an Object Literal

Trevon Allen
Trevon Allen
3,518 Points

Your countWords() method is not returning the correct number of words.

not sure why im getting this Bummer any assistance is appreciated

mystring.js
const myString = {
    string:"Programming with Treehouse is fun!",
  countWords: function () {
    return this.string.length
  }

}

1 Answer

Jonathan Hermansen
PLUS
Jonathan Hermansen
Courses Plus Student 25,015 Points

You should count the number of words in the string, not how long the string is. Hint: .split(" ")

Trevon Allen
Trevon Allen
3,518 Points

ahhh return this.string.split( ' ' ).length thank you that worked