Skip to content

Instantly share code, notes, and snippets.

/a.js

Created March 18, 2016 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/a044a343d8953e295f15 to your computer and use it in GitHub Desktop.
Save anonymous/a044a343d8953e295f15 to your computer and use it in GitHub Desktop.
function Animal(name, numLegs) {
this.name = name;
this.numLegs = numLegs;
};
var penguin = new Animal("Captain Cook", 2);
penguin.sayName();
penguin.prototype.sayName = function() {
console.log('Hi my name is ' + 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