Object Oriented Programming - Add Methods After Inheritance

I have a question on the syntax of this challenge.
I dont understand why the first Dog.prototype works but the second doesnt

 Dog.prototype.bark = function() {
 console.log("Woof!");
}; 

Dog.prototype = {
  bark: function() {
    console.log("Woof!");
  }
};


**Your code so far**


```javascript
function Animal() { }
Animal.prototype.eat = function() { console.log("nom nom nom"); };

function Dog() { }

// Only change code below this line
Dog.prototype = Object.create(Animal.prototype);
Dog.prototype.constructor = Dog

/*Dog.prototype.bark = function() {
 console.log("Woof!");
}; */

Dog.prototype = {
  bark: function() {
    console.log("Woof!");
  }
};

// Only change code above this line

let beagle = new Dog();

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36

Challenge: Object Oriented Programming - Add Methods After Inheritance

Link to the challenge:

I dont understand why it doesnt work. From my understanding the two code snippets I provided are the same so I dont get why Dog.prototype = {
bark: function() {
console.log(“Woof!”);
}
}; wouldnt work

let myObject = {};

myObject.addThisToTheObject = "Hello"
myObject.addAnotherThing = function() {return 'Greatings'}

console.log(myObject) // { addThisToTheObject: 'Hello', addAnotherThing: [Function] }

myObject = {oops: "this just reset the object to a new object!"}

console.log(myObject) // { oops: 'this just reset the object to a new object!' }

understood now thank you!

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