How increment a parameter with a method?

https://www.codecademy.com/paths/full-stack-engineer-career-path/tracks/fscp-javascript-syntax-part-ii/modules/fecp-practice-javascript-syntax-arrays-loops-objects-iterators/lessons/intermediate-javascript-coding-challenge/exercises/dog-factory

At the end of the above exercise, we’re asked to create a method eatTooManyTreats that aims to increase the value of the weight parameter. However, I didn’t understand how to make this method functional.

Here’s my code:

const dogFactory = (name, breed, weight) => {
  return {
    _name: name,
    _breed: breed,
    _weight: weight,
    get name() {
      return this._name;
    },
    get breed() {
      return this._breed;
    },
    get weight() {
      return this._weight;
    },
    set name(newName) {
      this._name = newName;
    },
    set breed(newBreed) {
      this._breed = newBreed;
    },
    set weight(newWeight) {
      this._weight = newWeight;
    },
    bark() {
      return 'ruff! ruff!';
    },
    eatTooManyTreats() {
      this._weight++;
    },
  }
}

And here’s is how I tried to call the method:

newDog = dogFactory('Joe', 'Pug', 28);
console.log(newDog.eatTooManyTreats());

The result is undefined.

If I change the eatTooManyTreats method and include a return, the result is same of the value I sent by newDog.

How can I call this method incrementing the weight?

Thanks!

You did successfully call the method to increment the weight, but the method itself doesn’t return anything, so it’s undefined when you try to log the return value.

Check this out:

console.log(newDog.weight);
newDog.eatTooManyTreats();
console.log(newDog.weight);