Jben13
7/13/2018 - 1:02 AM

functional class

functional class

const dog = {
name: 'Scout',
breed: ['Husky', 'German Shepherd'],
age: 4,
happiness: 50,
hunger: 10,
energy: 100,
};


//functional class
const Dog = function (name, breed, age,){
  const obj = {};

  obj.hunger = 10;
  obj.happiness = 50;
  obj.energy = 100;

  obj.name = name;
  obj.breed = breed;
  obj.age = age;

  obj.feed = function (food){
    if (obj.hunger - food > 0) {
      obj.hunger -= food;
    } else {
      obj.hunger = 0
    }
  };
  obj.nap = function (time) {
    if (obj.energy + time < 100) {
      obj.energy += time;
    } else {
      obj.energy = 100;
    }
};
  obj.play = function(time) {
    if (obj.happiness + time < 100) {
      obj.happiness += time;
    } else {
      obj.happiness = 100;
    }

    if (obj.energy - time > 0) {
      obj.energy -= time;
    } else {
      obj.energy = 0;
    }
};
  return obj;
};