Introduction to Objects II Penguins, Properties, and the Prototype


#1

got stuck dont know where is the error...........IIIII
need help...

function Penguin(name) {
this.name = name;
this.numLegs = 2;
}
// create your Emperor class here and make it inherit from Penguin
function Emperor(name){
this.name = name;
}
Emperor.prototype = new Penguin();
// create an "emperor" object and print the number of legs it
var emperor = new Emperor("billy"){
console.log(emperor.numLegs);
}


#2

Hi this part

var emperor = new Emperor("billy"){
console.log(emperor.numLegs);
}

remove the { }


#3

thanks a lot man..
i hardly think of that...changed my code may times but not work because of this { ....}
thank u


#4

@tatheerhussain,

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

#5

Yeah, well you're no help. Such cryptic answers go over our heads. If you'd just give us the direct code like a sensible person...

Course-maker.


#6

whas wrong in this code, introduction to object 2, 1st chapter an object review.

var james = {
job: "programmer",// add properties to this object!
married: false
};

function Person(job, married) {
this.job = job;
this.married = married;
}

var gabby = new Object("student", true);
function Person(job, married) {
gabby.job = "student";
gabby.married = true;
}


#7

this part

var gabby = new Object("student", true);
function Person(job, married) {
gabby.job = "student";
gabby.married = true;
}

You should Create a new gabby object using the Person constructor just like that

var gabby = new Person("student", true)