Skip to content

Instantly share code, notes, and snippets.

@robmint
Created May 31, 2022 05:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robmint/f1aea072019005234661fe294e440f8e to your computer and use it in GitHub Desktop.
Save robmint/f1aea072019005234661fe294e440f8e to your computer and use it in GitHub Desktop.
cat javascript for Luna
function Cat() { // cat factory, called a Constructor
this.furry = true; // this is the info that every cat has to start with
this.name = ""; // but can be changed
this.legs = 4;
}
cat = []; // make a new list of cats: [] means a numbered list starting at 0
for(var i=0; i<5; i++) { // go through the list creating 5 cats
cat[i] = new Cat(); // use the Cat() factory to make a new cat and store it in the list of cats
}
cat[0].name = "Lulu"; // set the name of cat[0]
cat[1].name = "Austin"; // set the name of cat[1]
console.log(cat); // print out the whole list of cats
console.log(cat.length); // print out how many cats we have
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment