Skip to content

Instantly share code, notes, and snippets.

@PatrickLandin
Created September 16, 2014 03:51
Show Gist options
  • Save PatrickLandin/da7629f2c0819037947c to your computer and use it in GitHub Desktop.
Save PatrickLandin/da7629f2c0819037947c to your computer and use it in GitHub Desktop.
Class code
<!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 += card.show();
};
};
var deck = document.getElementById('deck');
deck.innerHTML = this.cards;
}
function Card(suit, rank) {
this.suit = suit;
this.rank = rank;
this.show = function() {
return '<li class="cards">' + 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