Skip to content

Instantly share code, notes, and snippets.

@jnewman12
Created December 3, 2016 01:24
Show Gist options
  • Save jnewman12/5a6dfd3543092836bc336a00ca45dc21 to your computer and use it in GitHub Desktop.
Save jnewman12/5a6dfd3543092836bc336a00ca45dc21 to your computer and use it in GitHub Desktop.
Lab for JS Constructors and Classes

JS Constructors and Classes Lab


Part One

Make a deck of cards.

  • Make an array of suits.
  • Make an array of values.
  • Write a constructor function for Card which takes two arguments, suit and val. Include a stateValue method to return the card's suit and value in a concatenated string.
  • Using iteration, build a deck of cards.
  • Add an event listener to console.log the deck object and the deck length when a specific button is clicked (don't forget to create the button in your HTML!)

Part Two

Make a list of animals in a shelter.

  • Make a constructor function for animals that takes name, species, breed, and available as arguments.
  • Make three animals and save them each to variables.
  • Make an object to represent the shelter. Give it a name, location, and an empty list of animals.
  • Add the animals that you made in step 2 to the shelter that you made in step 3.
  • Add an event listener to console.log the shelter object when a specific button is clicked (don't forget to create the button in your HTML!)

Part Three

Make a list of animals in a shelter again, but this time, use prototypes.

  • Make a constructor function for animals that takes no arguments. Its only property is an identify function which returns a string stating its name and species.
  • Make a Cat prototype which inherits from Animal. The constructor function should take three arguments: name, available, and breed.
  • Repeat step 2 for Dog.
  • Make three animals using the Cat and Dog prototypes and save them each to variables.
  • Make an object to represent the shelter. Give it a name, location, and an empty list of animals.
  • Add the animals that you made in step 4 to the shelter that you made in step 5.
  • Add an event listener to console.log the shelter object when a specific button is clicked (don't forget to create the button in your HTML!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment