Skip to content

Instantly share code, notes, and snippets.

@brookr
Created September 17, 2014 06:30
Show Gist options
  • Select an option

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

Select an option

Save brookr/e01bfb10ddd993e434dc to your computer and use it in GitHub Desktop.
A deck of cards, modelled in HTML and JS
<!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