Created
September 17, 2014 06:30
-
-
Save brookr/e01bfb10ddd993e434dc to your computer and use it in GitHub Desktop.
A deck of cards, modelled in HTML and JS
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
| <!doctype html> | |
| <html> | |
| <head> | |
| <title> | |
| Deck of Cards | |
| </title> | |
| </head> | |
| <body> | |
| <ul id="deck" class="collection"> | |
| </ul> | |
| <script> | |
| function Deck() { | |
| this.cards = ''; | |
| for (var suit = 0; suit < 4; suit++) { | |
| for (var rank = 0; rank < 13; rank++) { | |
| var card = new Card(suit, rank); | |
| this.cards = this.cards + card.toHTML(); | |
| }; | |
| }; | |
| document.getElementById('deck').innerHTML = this.cards; | |
| } | |
| function Card(suit, rank) { | |
| this.suit = suit; | |
| this.rank = rank; | |
| this.toHTML = function() { | |
| return '<li class="card">' + this.suit + '-' + this.rank + '</li>'; | |
| } | |
| } | |
| var deck = new Deck(); | |
| </script> | |
| </body> | |
| </html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment