Skip to content

Instantly share code, notes, and snippets.

@philpoore
Forked from anonymous/a.js
Last active March 18, 2016 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philpoore/a5523baad36a33ac8577 to your computer and use it in GitHub Desktop.
Save philpoore/a5523baad36a33ac8577 to your computer and use it in GitHub Desktop.
function Animal(name, numLegs) {
this.name = name;
this.numLegs = numLegs;
};
Animal.prototype.sayName = function() {
console.log('Hi my name is ' + this.name);
};
var penguin = new Animal("Captain Cook", 2);
penguin.sayName();
var penguin = new Animal("Captain Cook", 2);
penguin.sayName();
/*
Create a class named Animal with two properties, name and numLegs.
The Animal constructor should have two arguments whose values are assigned to name and numLegs.
Next, change the prototype of Animal and add a method sayName that prints to the console
"Hi my name is [name]", where [name] is the value of name.
Click "Stuck? Get a hint!" for examples of how to create a class and how to add a method to an object's prototype.
Finally, we have provided the last two lines to test your constructor and sayName method. Don't change these!
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment