My code passes but doesn't print anything as required


#1

My following code does not print anything but is valid though, please help:

function Animal(name, numLegs) {
this.name = name;
this.numLegs = numLegs;
}
Animal.prototype.sayName = function() {
console.log("Hi my name is " + this.name);
};

// create a Penguin constructor here
function Penguin(name, numLegs){
this.name = name;
this.numLegs = numLegs;
};

// create a sayName method for Penguins here
Penguin.prototype.sayName = function(){
console.log("Hi my name is " + this.name);
};

// our test code
var theCaptain = new Penguin("Captain Cook", 2);
theCaptain.sayName();


#2

@bizbrar,
Have you tried....
++++ reset of session *****************
As you are manipulating with objects
under certain circumstances you can shoot your Browser in an
inconsistent state.

Therefor it is of an advantage to know that you have 2 reset facilities:

One is the use of the F5-key which does a refresh Browser

and

Two, select&copy your code
Then use the Reset Code button of the course-window,
then paste your code back in.

Addendum
General Notes:
Always refresh the browser after making corrections:
CTRL f5 ( if on Windows or Linux)
CMD r ( if on a MAC).
CTRL 0 to reset browser zoom


#3

@bizbrar,

But in this exercise they are trying to encourage you to think about

J a v a S c r i p t and it's == p r o t o t y p e - C h a i n ==

They want you to set up the chain:

        OBJECT
  Object.prototype
           ^
           |
  Animal.prototype  (( has the sayName Method))
           |                              ^
           |                              | 
           |                    Animal Class-Constructor
           ^                   | with this constructor
           |                   |  you can create Instance's of Animal
           |
           |    <<== You define this link in the Chain using
           ^            Penguin.prototype = new Animal();
           |
  Penguin.prototype ((is empty))
           |               ^
           |               | 
           |          Penguin Class-constructor
           ^                   | with this constructor
           |                   |  you can create Instance's of Penguin
   /Instance /      <---   using new Penguin("aName");
   | of      |
   | Penguin |
    The Penguin-Instance has access
     to Animal.prototype.sayName Method
     via the Penguin-prototype which is
      -chained- to the Animal-prototype.

#4

Wow, that's great, thanks for advising on the refresh.

I really appreciate it!