21/30


#1

how do i print out true on the last one?
// original classes
function Animal(name, numLegs) {
this.name = name;
this.numLegs = numLegs;
this.isAlive = true;
}
function Penguin(name) {
this.name = name;
this.numLegs = 2;
}
function Emperor(name) {
this.name = name;
this.saying = "Waddle waddle";
}

// set up the prototype chain
Penguin.prototype = new Animal();
Emperor.prototype = new Penguin();

var myEmperor = new Emperor("Jules");

console.log(myEmperor.saying); // should print "Waddle waddle"
console.log(myEmperor.numLegs ); // should print 2
console.log( myEmperor.isAlive!==this.isAlive); // should print true


#2

@alexyseu,

What you did, is you created a so-called prototype-chain
looking [bottom]->[up]

[Emperor]-prototype-of-[Penguin]-prototype-of-[Animal]-prototype-of-[object]
 name                   name(shadowed)         name(shadowed)
 saying                 numLegs 2              numLegs(shadowed)
                                               isAlive true

With

 var myEmperor = new Emperor("Jules");

you created a so-called Instance of the Emperor class of objects
resulting in an myEmperor object

   {  name: "Jules",
     saying: "Waddle waddle" }

From the myEmporer object you have
myEmperor.name => Jules
myEmperor.saying => Waddle waddle
and via the prototype-chain
myEmperor.numlegs (as property of the =Penguin= Object class constructor ) =>2
and
myEmperor.isAlive (as property of the =Animal= Object class constructor ) => true

There is a hasOwnProperty() - Method, with which you test if a found property
is a property of the object

for (var key in myEmperor) {
    console.log( key + " " + myEmperor.hasOwnProperty(key));
}

will give the [output]

name true
saying true
numLegs false
isAlive false