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

Dunno what to do

Need help

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

1 Answer

Sam Gord
Sam Gord
14,059 Points

i think the answer can look like something like this ;) -->

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