Object-Oriented Programming I
Exercise: Virtual Pet
Real pets are great, but they do have drawbacks. They smell. Your mum might be allergic to them. Maybe you just aren't allowed one in your flat.
To solve these problems, we're going to make our own JavaScript pets.
JavaScript pets are great. Because they're made of JavaScript, they can do literally anything, and they don't have any of the drawbacks of regular pets. They don't even pee or poo :poop: (unless you program them too, you weirdo).
The pets we're going to make will have the following features:
-
You can give them a name
-
They can get older
-
As they get older, they get hungrier and less fit
-
You can walk your pet to increase it's fitness. :runner:
-
You can feed your pet to decrease it's hunger. :pizza:
-
You can talk to your pet to see if it needs feeding or walking
-
If your pet gets too hungry or unfit, it will DIE :skull:
-
If your pet gets to 30 days old it will DIE :cry:
Essential Reading
Please read the Prototype / Constructor byte before you proceed.