During this exercise, you'll apply your knowledge of object-oriented programming (OOP) and prototypal inheritance.
Your goal is to create a zoo and add animals to it. Yes, you read that correctly--you're creating a zoo! You're going to one-up Matt Damon, whom just bought a zoo:
To make your zoo successful, you'll need to follow the following three steps:
Fork and clone this repository to here:
~/workspace
If workspace
doesn't exist, create it:
mkdir ~/workspace
You'll need to create two constructors:
Animal
Zoo
Place your code for each constructor in its appropriate file in ./src/
.
An instance of this constructor should have the following properties and methods:
name
: has a string as a valueage
: has an integer as a valuekind
: has a string as a value--e.g., "horse", "lion", or "pig."awake
: has aBoolean
value, and the default isfalse
speak()
: has a string as a value (e.g., a pig would return "oink!")growUp()
: adds one year to animal'sage
feed()
: if the animal is awake, return's the string"NOM NOM NOM"
wakeUp()
: changesawake
totrue
sleep()
: changesawake
tofalse
An instance of this constructor should have the following properties and methods:
name
: has a string as a valuelocation
: has a string as a valuestatus
: has a string as a value, default is"closed"
animals
: has an array as a value
changeLocation()
: updates value oflocation
open()
: updates value ofstatus
to"open"
close()
: updates value ofstatus
to"closed"
isOpen()
: returns aBoolean
value.addAnimal()
: ONLY if the zoo is open and the kind of animal is not already in the zoo, adds an animal toanimals
.removeAnimal()
: ONLY if the zoo is open, removes an animal fromanimals
.
When you're done, push your work to your forked repository. Then copy the URL of your forked repository and paste it into the LMS (learning management system).