Set the Child's Prototype to an Instance of the Parent - Please help

Set the Child's Prototype to an Instance of the Parent - Please help
0

#1

Tell us what’s happening:
What’s wrong with my code? It wants a , when I have a . inbetween Dog and Prototype in Dog.prototype. This makes no sense to me.
Please help, thank you.

Your code so far


function Animal() { }

Animal.prototype = {
  constructor: Animal,
  eat: function() {
    console.log("nom nom nom");
  }
};

function Dog() { }

// Add your code below this line
let Dog.prototype=Object.create(Animal.prototype);

let beagle = new Dog();
beagle.eat();  // Should print "nom nom nom"

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/object-oriented-programming/set-the-childs-prototype-to-an-instance-of-the-parent


#2

Look at the example for the Bird.prototype. Do you see a let in front of it? VAR, LET, and CONST are only for declaring variables and not prototypes.


#3

Thank you very much! Randell, you seem experienced, tell me, does it happen often that you miss simple stuff like that even when you’re “professional” at coding? Feels like I get blind for mistakes in my own code because I’m trying so hard to spot them. :laughing:


#4

We are human, so we will make mistakes. The more experience you have as a coder (and making mistakes), the faster you will be able to recognize the mistakes when they occur.