Created
June 12, 2014 05:23
-
-
Save brookr/7bd7b8328118760f2d18 to your computer and use it in GitHub Desktop.
Example code from in-class live coding of a deck of cards
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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