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

Alex Shah
Alex Shah
5,420 Points

Add a method to the object literal called countWords(). countWords() should return the number of individual words in the

const myString = { string: "Programming with Treehouse is fun!" countwords:function(){ countWords(myString.length) }

}

mystring.js
const myString = {
    string: "Programming with Treehouse is fun!"
  countwords:function(){

  }

}

1 Answer

Steven Parker
Steven Parker
203,693 Points

Oddly, some of the code shown in your question didn't show up in the formatted code sample. But based on what's in the question:

  • object properties must be separated by a comma
  • "countwords" should be spelled "countWords" (with a capital "W")
  • the object should not reference itself by name
  • the method should not call itself
  • the method should return a value