Skip to content

Instantly share code, notes, and snippets.

@brookr
Created June 12, 2014 05:23
Show Gist options
  • Select an option

  • Save brookr/7bd7b8328118760f2d18 to your computer and use it in GitHub Desktop.

Select an option

Save brookr/7bd7b8328118760f2d18 to your computer and use it in GitHub Desktop.
Example code from in-class live coding of a deck of cards
<script>
function Deck() {
this.cards = [];
this.count = function() {
return this.cards.length;
}
this.init = function() {
for (s = 1; s <= 4; s++) {
for (r = 1; r <= 13; r++) {
this.cards.push(new Card(r, s));
}
}
}
}
function Card(rank, suit) {
this.rank = rank;
this.suit = suit;
this.show = function() {
console.log(this.rank + " of " + this.suit);
}
}
d = new Deck();
d.init();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment