Last active
August 30, 2018 16:46
-
-
Save maxvolovikov/ee0c00298df5c844ca76abacfb4da015 to your computer and use it in GitHub Desktop.
Prototypal class object creator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Dogs = function (name, breed, age, happiness, hunger, energy){ | |
var dog = Object.create(Dogs.prototype) | |
dog.name = name; | |
dog.breed = breed; | |
dog.age = age; | |
dog.happiness : happiness; | |
dog.hunger = hunger; | |
dog.energy = energy; | |
return dog; | |
} | |
Dogs.prototype.feed = function(food){ | |
if(this.hunger - food > 0) { | |
this.hunger -= food; | |
} else { | |
this.hunger = 0; | |
} | |
}; | |
Dogs.prototype.play = function(time){ | |
if(this.happiness + time < 100) { | |
this.happiness += time; | |
} else { | |
this.happiness = 100; | |
} | |
if(this.energy - time > 0) { | |
this.energy -= time; | |
} else { | |
this.energy = 0; | |
} | |
}; | |
Dogs.prototype.nap = function(time) { | |
if(this.energy + time < 100) { | |
this.energy += time; | |
} else { | |
this.energy = 100; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment