I am trying something new and I am having issues with my current idea. I am still new and trying to grasp the basics of using objects so I might be completely off base with this but I thought I might ask you all if what I am doing has any chance of working.
// first we can make the instructor
function Rabbit(adjective) {
this.adjective = adjective;
this.describeMyself = function() {
console.log("I am a " + this.adjective + " rabbit");
};
}
// now we can easily make all of our rabbits
var rabbit1 = new Rabbit("fluffy");
var rabbit2 = new Rabbit("happy");
var rabbit3 = new Rabbit("sleepy");
for (i=1;i<=3;i++){
//console.log("rabbit"+i);
var tempRabbit = "rabbit"+i;
console.log(tempRabbit.adjective);
}
I want to use the for loop to add the number to each rabbit object i created and then print out the adjective it has passed into it.
Most people store rabbits in arrays. This makes it much easier to manage the growing population of these marvelous creatures.
Here’s an example:
You can also push new rabbits into the array you’ve got. There’s special method for that:
If you need more information on how to use arrays to simplify the management of your stock, refer to this documentation: Javascript Arrays