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 Practice Object Basics in JavaScript Practicing Object Basics Practice Adding a Method to an Object Literal

Samuel Kleos
seal-mask
.a{fill-rule:evenodd;}techdegree
Samuel Kleos
Front End Web Development Techdegree Student 13,409 Points

I declared the method differently. Is this proper?

Hello,

Hope you're well. I appreciate you taking a look at this. :)

I often mix up object literal method declaration, and class method declaration like below:

class Pet {
    constructor(animal, age, breed, sound) {
        this.animal = animal;
        this.sound = sound;
    }
    speak() {
        console.log(this.sound);
    }
}
const casper = new Pet('cat','meow')

Is my solution to the code challenge correct?

mystring.js
const myString = {
    string: "Programming with Treehouse is fun!",
  countwords() {
    this.string.split(" ").length;
  }
}

1 Answer

Steven Parker
Steven Parker
231,269 Points

You're close, but the instructions ask for a method named "countWords" (with a capital "W") but this code has it in all lower case.

Also, the method needs to return the length.