Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Dec 6th, 2018 60 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. var extend = function (obj1, obj2) {
  2.   for (var key in obj2) {
  3.     obj1[key] = obj2[key];
  4.   }
  5. }
  6.  
  7. const dog = {
  8.   name: 'Scout',
  9.   breed: ['Husky', 'German Shepherd'],
  10.   age: 4,
  11.   happiness: 50,
  12.   hunger: 10,
  13.   energy: 100,
  14. };
  15.  
  16. var Dog = function (dogObj) {
  17.   extend(this, dogObj);
  18. }
  19.  
  20. Dog.prototype.feed = function (food) {
  21.   if (dog.hunger - food > 0) {
  22.     dog.hunger -= food;
  23.   } else {
  24.     dog.hunger = 0;
  25.   }
  26. }
  27.  
  28. Dog.prototype.play = function (time) {
  29.   if (dog.happiness + time < 100) {
  30.     dog.happiness += time;
  31.   } else {
  32.     dog.happiness = 100;
  33.   }
  34.   if (dog.energy - time > 0) {
  35.     dog.energy -= time;
  36.   } else {
  37.     dog.energy = 0;
  38.   }
  39. }
  40.  
  41.  
  42. Dog.prototype.nap = function (time) {
  43.   if (dog.energy + time < 100) {
  44.     dog.energy += time;
  45.   } else {
  46.     dog.energy = 100;
  47.   }
  48. }
  49.  
  50. var myPetScout = new Dog(dog);
  51. console.log(myPetScout);
  52. console.log(myPetScout instanceof Dog);
  53. console.log(myPetScout.feed)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top