How increment a parameter with a method?

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() {

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

newDog = dogFactory('Joe', 'Pug', 28);

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?


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: