CODE CHALLENGES: INTERMEDIATE JAVASCRIPT dogFactory()

please can someone help me what i do wrong in the last step when i had create a eatTooManyTreats function when i try to run this function by call it like this : const dolf = dogFactory(‘Dolf’,‘pitbull’,10)
console.log(dolf.eatTooManyTreats()) it run me “undefined” please can someone help me to fix it and this my code below :

// Write your code here:
const dogFactory = (name, breed, weight) => {
 return {
   _name:name,
      get name(){
   return this._name
 },
 set name(newName) {
   this.name = newName
  },
   _breed:breed,
    get breed() {
     return this._breed
   },
   set breed (newBreed) {
    this.breed = newBreed
     },
   _weight:weight,
  get weight() {
       return this._weight
     },
     set weight(newWeight) {
     this.weight = newWeight
     },
     bark(){
       return "ruff! ruff!"
     },
     eatTooManyTreats() {
     this._weight++ 
     }
    
     
 }
}
const dolf = dogFactory('Dolf','pitbull',10)
console.log(dolf.eatTooManyTreats())

 
  


Your eatTooManyTreats() function doesn’t really return anything, it’s just assigning a new value to the weight attribute of your object.

When you do this:

You are basically trying to log whatever value that call to the function returns, but since it doesn’t return anything, undefined is logged to the console.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.